htaccess的重写规则重写CSS文件重写、规则、文件、htaccess

2023-09-02 11:42:40 作者:装逼卖萌无所不能

我有一个重写规则,使pretty的网址,但其重写CSS,JS等文件了。

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

我想重写

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

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

我想这样

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]

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.

推荐答案

尝试把这个规则在 /example/post/.htaccess

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

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