blubbering
blubbering

Reputation: 327

mod_rewrite multiple RewriteCond conflict

I have a Problem with mod-rewrite.

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent]  
    # For all files not found in the file system, reroute the request to the
    # "index.php" front controller, keeping the query string intact
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
</IfModule>
# IE Cache fix?
ExpiresActive On
ExpiresDefault A1
Header append Cache-Control must-revalidate

Redirecting doesn't work and no Styles or Images are showing.

If those three lines are comment out, it works:

#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^ index.php [L]

But I need those to redirect any wrong entery to the root. How does this work together? Or why it doesen't work like this?

Upvotes: 1

Views: 199

Answers (1)

Jon Lin
Jon Lin

Reputation: 143896

Try adding a L flag to your redirect. If you don't have one, the request will get flagged as a redirect and mod_rewrite will continue to run the rest of your rules. So this line needs an L:

RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]  

If you have relative URL issues with your images or styles, try adding this to the header of your pages:

<base href="/" />

Upvotes: 1

Related Questions