我正在根据这个问题工作 (Redirect .php urls to urls without extension) 但这会将我发送到根文件夹。
RewriteEngine On
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
例如我的原始网址http://www.website.com/products/abc.php
重定向后,它会将我发送到http://www.website.com/abc
答案 0 :(得分:1)
这是可以处理子文件夹的通用规则
Options -MultiViews
RewriteEngine On
# browser requests PHP
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+/)?([^/\s\?&]+)\.php
RewriteRule ^ /%1%2 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ /$1.php [L]