开发者

mod_rewrite - error with 2 variables

just a quick one, I'm using this rule and it works fine:

RewriteRule ^([^/.]+)$ /profile.php?id=$1

so whatever come to mysite.com/anything will be read as mysite.com/profile.php?id=anything That's all good.

Then I need to add another variable so I used:

RewriteRule ^([^开发者_如何学JAVA/.]+)/([^/.]+)$ /profile.php?id=$1&vid=$2 

Which kind of works but it doesn't load any css, js, external php... I guess that's why it's looking in a different folder, I don't know how to tell it get those other files from the root folder.

Any ideas?


That's because you are creating virutal folders using the htaccess. If you want to load your CSS and JS properly, either use absolute paths or add ../ before your relative path (which means "one folder up").

Another possibility is to add <base href="www.example.com">. Which will cause all new requests (for images, external files, etc) to be relative to that path, and not the current address.


You can add

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

to do not rewrite URL if there are files with this URL


Add next 2 lines befor RewriteRule

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜