views:

792

answers:

5

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??

A: 
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

Chacha102
A: 

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
A: 

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
Bryan Migliorisi
A: 

Hi there

am having a similar problem When i use a rewriterule like ^items/shuffle/?$ index.php?shuffle=true, the css and js are not loading. My file structure is somthing like this

/myprojects/project1/production/index.php
/myprojects/project1/production/css/master.css
/myprojects/project1/production/js/all-js-goes-here

When i use the RewriteRule mentioned earlier, index.php?shuffle=true loads but all the css and js cant be found. i even tried adding a Rewritebase /myprojects/project1/production/.

I cant use an absolute path to my css cause, i am still developing this website and the path could be different once i host it, so using something like /myprojects/project1/production/css/master.css to include the css file does'nt sound right to me.

I am not too good with .htaccess, just trying to learn it.

Any help is highly appreciated.

Thanks Vru

A: 

Any body please?!