重定向到错误的URL

时间:2017-05-04 14:16:46

标签: .htaccess url

我一直在网站上工作,并且最近对我的.htaccess文件进行了一些更改。每当我去localhost / company时它都会正确地重定向我,但是现在每当我去localhost / company时它会将我重定向到http://localhost/company.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php//并出现404页面错误,显然该页面不存在。它将我重定向到错误的URL。

我很确定这个问题来自我的.htaccess文件,我已经从3个月前回滚过.htaccess了,这个问题仍然存在。

这是我的.htaccess:

RewriteEngine On
RewriteRule ^config\.php - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
ErrorDocument 404 /404.php
RewriteRule ^i(/.*)?/company /company [L,NC]


# disable directory browsing
Options All -Indexes

<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh|svn|7z|zip|rar|gz|tar)$">
 Order Allow,Deny
 Deny from all
</FilesMatch>

我希望你能帮助我!谢谢!

1 个答案:

答案 0 :(得分:0)

如评论中所述,如果contact.php不存在,您可能会获得此重定向循环。

RewriteEngine On
RewriteRule ^config\.php - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

尝试将前几行更改为(假设此.htaccess文件位于文档根目录中):

RewriteEngine On
RewriteRule ^config\.php - [R=404,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php -f
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php [L]

这只是在重写之前首先检查文件是否存在。我还在这两个指令中添加了Llast) - 我无法看到以后的任何规则都依赖于这些指令吗?

相关问题