.htaccess rewriting rule rewriting css files

笑着哭i 提交于 2019-12-12 02:27:40

问题


I have a rewrite rule to make pretty url but its rewriting css, js and other files too.

I want to rewrite

http://localhost/example/post/?postid=af1ub4zu4y&title=this-is-the-first-post.html

to

http://localhost/example/post/af1ub4zu4y/this-is-the-first-post.html

I am trying this way

Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^post/([^/]*)/(.*\.html) /example/post/?postid=$1&title=$2 [QSA,L,B]

also tried like these

RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^post/([^/]*)/(.*\.html) /example/post/?postid=$1&title=$2 [QSA,L,B]

and

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^.*\.(css|jpe?g|gif|png|js|ico)$ [NC]
RewriteRule ^post/([^/]*)/(.*\.html) /example/post/?postid=$1&title=$2 [QSA,L,B]

But none of these solution are working for me. Please see and suggest any possible way to do this.


回答1:


Try placing this rule in /example/post/.htaccess:

Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /example/post/

RewriteRule ^([^/]+)/([^/.]+\.html?)$ ?postid=$1&title=$2 [QSA,L,B,NC]


来源:https://stackoverflow.com/questions/32815539/htaccess-rewriting-rule-rewriting-css-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!