[英]htaccess- unable to remove file extension from url php
I am trying the following rules to remove file extension from file name but the problem is it is showing that it is removed but when I login again it is not redirecting to my home page. 我正在尝试以下规则从文件名中删除文件扩展名,但问题是它已被删除,但是当我再次登录时,它没有重定向到我的主页。
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase \
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
Thank You 谢谢
In your redirection just type in page name with no extension, eg. 在重定向中,只需输入不带扩展名的页面名称即可。 header('Location: index');
header('Location:index'); or redirect_user('index');
或redirect_user('index'); and use the code below in your .htaccess file.
并在您的.htaccess文件中使用下面的代码。 now the link on the browser will be say "localhost/index"
现在浏览器上的链接将显示为“ localhost / index”
RewriteEngine on
RewriteRule ^([^./]{3}[^.]*)$ /index.php?page=$1 [QSA,L]
I think your rules are just a little bit off. 我认为您的规则有些偏离。 You are using
THE_REQUEST
to redirect php extension to non php extension but you are not using a /
after %1
in the rewriterule so when the next rule is read it is not matching because it will only internally redirect if there is a /
in that rule. 您正在使用
THE_REQUEST
将php扩展名重定向到非php扩展名,但是您在重写器中未在%1
之后使用/
,因此,在读取下一条规则时,它不匹配,因为只有在该规则中包含/
时,它才会内部重定向。 So either add a forward slash after %1 in the second rule or make the backslash optional in the last rule. 因此,可以在第二条规则的%1之后添加正斜杠,或者在最后一条规则中将反斜杠设置为可选。 I would just make it optional in last rule so it will match either way.
我只是在最后一条规则中将其设置为可选,因此它将以任何一种方式匹配。
Try this update and see how it works. 尝试此更新,并查看其工作方式。
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /([^&\ ]+).php [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ $1.php [NC,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.