2015-09-28 214 views
0

我有一个重写规则,使漂亮的网址,但它的重写CSS,JS和其他文件。.htaccess重写规则重写css文件

我想重写

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] 

也试过这样的

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] 

但是,这些解决方案都为我工作。请参阅并提出任何可能的方法来做到这一点。

+0

什么是你想改写?提供样品。另外,请确认htaccess是否正在加载; mod-rewrite is enabled etc., – hjpotter92

+0

@ hjpotter92请参阅更新,htaccess被加载并且mod-rewrite被启用 –

+0

是的,我得到了404错误 –

回答

0

试着将这个规则在/example/post/.htaccess

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

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

获取404错误。 –

+0

是的,它启用了500错误。 –

+0

我也有这条规则,它工作正常'RewriteCond%{REQUEST_FILENAME}!-d RewriteCond%{REQUEST_FILENAME}!-f RewriteRule^view /([^ /] *)$/example/view /?hash = $ 1 [QSA,L] ' –