我有一个网址为
的网站我添加了用于从网址中删除.php扩展名的代码,如下所示
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
如果有人使用网址进行搜索
如果有人用http://mywebsite.com/abc/搜索,我需要使用htaccess强制将其重定向到http://mywebsite.com/abc
答案 0 :(得分:0)
#删除斜杠
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/$ /$1 [L,R=301]
答案 1 :(得分:0)
您可以使用此:
RewriteEngine on
#redirect and remove trailing slash
#from all URIs except directories "!-d"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/?$ /$1 [L,R=301]
#remove .php extension
#this allows you to access php files without extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)/?$ /$1.php [QSA,L]