使用htaccess </subfolder-name>将子文件夹重定向到root,其中包含<subfolder-name> .html

时间:2014-05-02 11:39:47

标签: html .htaccess subdirectory

我的网站有

之类的链接
domain-name.com/pages/contact-us/
www.domain-name.com/pages/contact-us/
domain-name.com/pages/about-us/
www.domain-name.com/pages/about-us/
and other pages ...

我正在寻找的是如何使用htaccess将它们永久地重定向到相同的subfoldername.html。例如,上面的所有链接都应该重定向到

domain-name.com/contact-us.html
www.domain-name.com/contact-us.html
domain-name.com/about-us.html
www.domain-name.com/about-us.html
also for other pages, otherwise if page not found to root index.html .

提前致谢。

1 个答案:

答案 0 :(得分:0)

尝试以下

RewriteEngine On
RewriteCond %{REQUEST_URI} ^(/pages/(.*[^/])/?)$
RewriteRule ^(.*)$ /%2.html [L,R=302]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.html [L,R=302]

前三行将删除文件夹pages。如果有斜杠,则会将其删除。如果请求文件不存在,最后三行将重定向到/index.html

相关问题