Forum Moderators: phranque
It seems to be working fine, but just wanted to run the code by you to double check I'm doing the right thing..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
Redirect /htaccess-url-redirect.html http://www.mydomain.com/
</IfModule>
does this look fine?
And is this the right thing to do?
[edited by: jdMorgan at 5:33 am (utc) on Feb. 10, 2006]
[edit reason] De-linked. [/edit]
1) Your <IfModule mod_rewrite.c> container includes a Redirect directive, which is not included in mod_rewrite.
2) Not sure why you'd want the [NC] flag on the first RewriteCond...
3) Because you have mixed mod_rewrite and mod_alias directives, their order of execution cannot be controlled within this code -- This will be controlled by the reverse LoadModule order on Apache 1.x, or by the module priority in Apache 2.x.
Jim
I did initially use
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
but it produced an error on my site and locked out access...
Found this other piece of code and it seems to work fine, at least does the change I want...
I would be happy to use a tighter / more sensible piece of code if you would recommend that..
You assistance would be apprieciated..
[edited by: jdMorgan at 2:43 pm (utc) on Feb. 10, 2006]
[edit reason] De-linked. [/edit]
did initially useOptions +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ [domain.com...] [L,R=301]but it produced an error on my site and locked out access...
the code is copied and your directives don't make much sense to me ...
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
The two samples of code are similar in behaviour, except that your first-posted code redirects *anything except* the canonical domain to the canonoical domain, while the second sample redirects only the non-canonical domain to the canonical domain. Which you use depends largely on your future plans; If you intend to add a bunch of subdomains later, you might want to use the second example. If however, you don't plan to add more subdomains, the first-posted code (less the NC flag) would catch more non-canonical domain variants.
A more correct form for your first example would be:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>
Redirect /htaccess-url-redirect.html http://www.example.com/
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^htaccess-url-redirect\.html(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>
Using the first option gives the error ..
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, sysadmin@greatserversdns2.co.uk and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
--------------------------------------------------------------------------------
Apache/1.3.33 Server at example.com Port 80
the <IfModule mod_rewrite.c> option works fine?