[英]How to target all .html URLS except index.html in htaccess
我目前在我的Wordpress htaccess文件中有此文件:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\\.html?$ / [NC,R,L] RewriteEngine On RewriteBase / RewriteRule ^index\\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> #RedirectMatch 301 (.*)\\.html$ $1/
我正在嘗試將所有.html重定向到沒有任何文件擴展名的URL,即www.example.com/about.html到www.example.com/about/。
該代碼在/index.html重定向到/的情況下正常工作
上面的注釋代碼( RedirectMatch 301 (.*)\\.html$ $1/
)應該可以將.html重定向到漂亮的URL,但是它也可以用於index.html,而不是將其重定向到/,而是將其重定向到/指數
有沒有一種方法可以壓縮我的代碼並執行我想做的事情?
像這樣:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html?$ / [NC,R,L]
# redirect every .html except index.html
RewriteRule ^(?!index\.html$)(.+)\.html?$ /$1 [NC,R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.