Regex htaccess没有';不能在服务器上工作,但可以在本地主机上工作(删除php扩展)
我想知道这段代码有什么问题,因为上次它在服务器和本地主机上都运行得很好。但现在它在服务器上根本不起作用 下面是我的代码:Regex htaccess没有';不能在服务器上工作,但可以在本地主机上工作(删除php扩展),regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我想知道这段代码有什么问题,因为上次它在服务器和本地主机上都运行得很好。但现在它在服务器上根本不起作用 下面是我的代码: 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 /my
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。它可以在本地主机上工作,但不能在服务器上工作。发生了什么事?您的.htaccess中有一行
RewriteBase
:
RewriteBase /mydomain/
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]
如果live server上没有mydomain
文件夹:
RewriteBase /
RewriteBase
表示从DocumentRoot
访问.htaccess的当前目录的相对路径
完全访问:
RewriteBase /mydomain/
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 None
,则它不会反映您在.htaccess文件中所做的更改您的服务器是否需要重写库(或具有正确的库)?此外,由于您盲目地在请求中添加.php,即使请求的文件不是以.php结尾的,您最终也会出现500个服务器错误。live server上是否也有/mydomain/
文件夹?@anubhava不,我这里没有任何文件夹。所以我应该删除?如果可以的话,你能在下面写一个答案吗?ThanksIt仍然不起作用。因为它没有显示任何东西。我保证index.php文件来自DocumentRoot。请检查我的更新代码。确保.htaccess
和.php
文件都位于DocumentRoot
中。仔细检查live server上的DocumentRoot
是什么