1
我需要301将所有以.php结尾的URL重定向到非扩展版本。但重写规则需要与现有的重写规则配合使用。htaccess从多个正斜杠的URL中删除.php扩展
# ==== REWRITE URLS ====
RewriteEngine On
# pass through root
RewriteRule ^(index\.php|Sitemap\.xml)?$ - [L]
# no more/so add extension
RewriteCond $1 !/
RewriteCond $1 !\.php$
RewriteCond ${REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /$1.php [L]
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^(_assets|_css|_fonts|_includes|_scripts)($|/) - [L] #exclude these folders using the 'last: L' flag
RewriteRule ^(.*)/(.*)$ /$1-$2 [L]
这是此题的延伸here。
所以期望的结果是:
domain.com/region/brand/more-content-here.php
永久重定向到:
domain.com/region/brand/more-content-here
但获取实际的文件在:
domain.com/region-brand-more-content-here.php
尝试了一些不同的想法,但他们没似乎不符合现有规则,而htaccess并不是我的力量。也需要它是查询字符串友好。任何帮助,将不胜感激。
完美!谢谢。我所需要的只是第一步,因为#2已经在现有规则中涵盖了。 – Dodo