htaccess rewrite rule not loading site content

你。 提交于 2019-12-12 04:28:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!