问题
I am struggling with .htaccess rewrite rules. Let's say I have this URL.
localhost/site/index.php
and I want to rewrite it as this URL
localhost/site/tutorial
I would use this RewriteRule
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^tutorial/(.*)$ /up/index.php
The page works, but the CSS files don't load.
Also, if I have a URL like this:
index.php?page=home
Then I would have to parse through that URL to get 'home' not using $_GET anymore correct??
回答1:
Just use absolute URLs for your CSS file, or at least reference from domain root.
http://www.mysite.com/css/myCssFile.css
or
/css/myCssFile.css
回答2:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^tutorial/(.*)$ /up/index.php
This will rewrite anything that goes to the tutorial directory as /up/index.php
, which means that unless you host your CSS file at that location, it won't work. If your css file is at /tutorial/css.css
, it will redirect it to /up/index.php
You would have to parse through the %QUERYSTRING% in order to redirect based on index.php?page=home
回答3:
So the CSS files are not loading because you are changing the location of the served file.
So if you are linking to ./css/style.css => ^/tutorial/css/style.css is not the same as /up/css/style.css
And you can retain the get if you rewrite:
RewriteRule ^tutorial/(.*)?(.*)$ /up/index.php?$2
来源:https://stackoverflow.com/questions/1274001/htaccess-rewrite-rule-not-loading-site-content