繁体   English   中英

htaccess在服务器中不起作用,但在本地主机中起作用(删除php扩展名)

[英]htaccess doesn't work in server but working in localhost (Remove php extension)

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

这是我的代码如下:

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,本地主机文件夹是mydomain。 它可以在localhost上运行,但不能在服务器上运行。 发生了什么?

您的.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服务器:/etc/httpd/conf/httpd.conf)中进行更改

# 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文件中所做的更改

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM