views:

41

answers:

3

I have this rewrite rule to access profile.php?user=username with mysite.com/username..

Problem with this is that it ignores my css, even if I use the full URL and whats weird is that its the same if i go to the regular url, profile.php?user=username. But If i remove my htaccess file the css works.

RewriteEngine on
RewriteRule (.*) profile.php?user=$1 [QSA,L]

Whats the problem here? Thanks in advance :>

+2  A: 

You could use a condition to only fire your rule if the URL you are attempting to fetch doesn't resolve to a file or directory

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) profile.php?user=$1 [QSA,L]

This will stop a request for foo.css being rewritten as profile.php?user=foo.css

Paul Dixon
A: 

Your rule will rewrite any request, even the request for your css file.

You will also need a RewriteCond like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) profile.php?user=$1 [QSA,L]

This will redirect only if there is no file that matches the request.

innaM
A: 

Remember that the request for the CSS file is a request too, and your rule is rewriting the request for whatever.css to profile.php?user=whatever.css

Draemon