Php .htaccess mod_重写

Php .htaccess mod_重写,php,html,.htaccess,mod-rewrite,Php,Html,.htaccess,Mod Rewrite,您好,我正在努力使它,以便当您访问我的网站时,您不必把.php放在最后,这是我正在使用的,但它不工作godaddy托管 Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php 我今天刚刚添加了选项+FollowSymlinks,但仍然不起作用。 非常感谢我想说 Rew

您好,我正在努力使它,以便当您访问我的网站时,您不必把.php放在最后,这是我正在使用的,但它不工作godaddy托管

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
我今天刚刚添加了选项+FollowSymlinks,但仍然不起作用。 非常感谢

我想说

RewriteCond %{REQUEST_FILENAME}\.php -f

这是不必要的。那是干什么用的?

我还不知道下面的符号链接是干什么的,但其余的都是这样做的:

RewriteEngine On            <-- activates mod rewrite
RewriteCond %{REQUEST_FILENAME} !-d  <-- condition that says: request filename is not directory
RewriteCond %{REQUEST_FILENAME}\.php -f  <-- condition that says: request filename with the appendix .php is a file
RewriteRule ^(.*)$ $1.php  <-- take anything you get and put a .php behind it
用人的话来说: 如果请求的文件名不是目录,并且如果您将.php附加到该文件名,并且该文件是一个现有文件,则执行重写规则,将.php附加到请求的文件

这适用于我的XAMPP:

<IfModule mod_rewrite.c>
    RewriteEngine On            
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

这将避免无限递归,因为只有请求被重写,并且可以正确地映射到现有的.php文件上。这决不是不必要的!它可以防止类似test.html的内容被重写为test.html.php!!您确定mod_rewrite已启用且正常工作吗?你尝试过其他规则吗?我是新手,如何启用mod_rewrite@Matthew卡特:试试一个非常简单的规则,比如重写规则^http://example.com/?.i 有自定义错误页面,如果这可能会影响anything@Matthew卡特:是否有一个同名的目录,这样第一个条件就可能无法满足?