问题
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