简体   繁体   English

文件扩展名后的斜杠无法重定向

[英]Slash after file extension can not be redirected

I am using these htaccess code to remove and redirect php extension to without file extension. 我正在使用这些htaccess代码删除php扩展名并将其重定向到没有文件扩展名的地方。

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

Then I try to use another slightly different code 然后我尝试使用另一个稍微不同的代码

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.+)\.[a-zA-Z0-9]+$ $1 [R=301,L]

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

Both code produce same problem, if try to access 如果尝试访问,两个代码都会产生相同的问题

  1. domain.com/other/content.php goes to domain.com/other/content (200 response) domain.com/other/content.php转到domain.com/other/content(200个响应)

Now here is strange behaviour, if try to access 现在,如果尝试访问,这是一种奇怪的行为

  1. domain.com/other/content.php/ goes to domain.com/other/content.php/ (200 response not 404) domain.com/other/content.php/转到domain.com/other/content.php/(200响应而不是404)

  2. domain.com/other/content.php/any-word goes to domain.com/other/content.php/any-word (200 response not 404 error) domain.com/other/content.php/any-word转到domain.com/other/content.php/any-word(200响应而不是404错误)

All other redirect work perfectly, besides this problem. 除此问题外,所有其他重定向都可以正常工作。 Can any one help with both code, I need both code rectification, as I have two different site with both htaccess rule. 任何人都可以同时使用这两个代码吗,我需要两个代码都更正,因为我有两个使用htaccess规则的不同站点。

If I keep both code 如果我保留两个代码

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

Plus, I add new code then it works 另外,我添加了新代码然后就可以了

RewriteEngine On
RewriteCond %{THE_REQUEST} /([^.]+)\.php/? [NC] 
RewriteRule ^ /%1/ [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /$1.php [L,NC]

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

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