开发者

How to write .htaccess mod_rewrite rules for these cases?

开发者 https://www.devze.com 2023-01-30 11:49 出处:网络
Want to forward开发者_StackOverflow the following: localhost/bla/index.html -> localhost/index.php?s=bla/index.html

Want to forward开发者_StackOverflow the following:

localhost/bla/index.html -> localhost/index.php?s=bla/index.html
localhost/blub.html -> localhost/index.php?s=blub.html
localhost/blog.html?site=10 -> localhost/index.php?s=blog.html&site=10
localhost/folder -> localhost/index.php?s=folder

but I only want do redirect .html and folders.


RewriteCond %{REQUEST_URI} .html$ [OR]
RewriteCond -d
RewriteRule (.*) /index.php?s=$1 [L,QSA]

Only if the uri ends with ".html" or if it's a folder, it rewrites the entire uri into the ?s= query string. The QSA flag should make sure that query strings on .html files (?site=10) are added to the new url as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消