Reputation: 2141
I am working on a website and i am faced with a big issue is:
(Note: the key thing here is it can work for infinite number of subfolders or pages as far as its the same root domain)
Now this is what i have:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
Options -Multiviews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(candidates|css|employers|layout|pics|securimage)/?$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteRule ^([^/]+)/?$ employers/page.php?page=$1 [L]
</IfModule>
The issues am having with what i have above are:
It does not redirect http://www.example.com/ to http://example.com.
It seems to rewrite well for http://www.example.com/name but when i have a url with one of the exceptions like http://example.com/css it changes the url to http://example.com/css/?page=css.
Please how can i fix this.
Thank you so much.
Upvotes: 1
Views: 411
Reputation: 13408
You have to separate your conditions ans rewrite rules:
For the www subdomain:
RewriteCond %{HTTP_HOST} ^www.example.tld$
RewriteRule ^(.*) http://example.tld/$1 [QSA,R=301]
then for the QSA redirection, except if the file exists:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ employers/page.php?page=$1 [L]
Upvotes: 0