htaccess在服务器中不起作用,但在localhost中工作(删除php扩展)



我想知道这段代码有什么问题,因为上次它在服务器和本地主机中都运行良好。但是现在它在服务器中根本不起作用。

这是我下面的代码:

RewriteEngine on
RewriteBase /mydomain/
# Return 404 if original request is /mydomain/index.php
RewriteCond %{THE_REQUEST} .php
RewriteRule ^ - [L,R=404]
# Rewrite /mydomain/index to /mydomain/index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^./]+)/?$ $1.php [L]

我的域名是 mydomain.com,本地主机文件夹是我的域。它在本地主机中工作,但在服务器上不起作用。发生了什么事情?

你的 .htaccess 中有这样一行RewriteBase

RewriteBase /mydomain/

如果实时服务器上没有mydomain文件夹:

RewriteBase /

RewriteBase表示从 DocumentRoot 到 .htaccess 当前目录的相对路径。

完整的 .htaccess:

RewriteEngine on
RewriteBase /
# Return 404 if original request is /mydomain/index.php
RewriteCond %{THE_REQUEST} .php
RewriteRule ^ - [L,R=404]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

更改httpd.conf文件 (linux server :/etc/httpd/conf/httpd.conf) for

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
    AllowOverride All

如果设置了AllowOverride None,它不会反映您在 .htaccess 文件中所做的更改

最新更新