Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Rewrite non www

Posted on 2013-01-16
2
Medium Priority
?
266 Views
Last Modified: 2013-01-17
I'm going to be adding a .com.au domain and is not working correctly

If you request mydomain.com.au it routes to www.mydomain.com
instead of www.mydomain.com.au

I added the "$" to terminate, is that not correct?

RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteRule ^/(.*)$ http://www.mydomain.com [R=301,NC,L]

RewriteCond %{HTTP_HOST} ^mydomain.com.au$ [NC]
RewriteRule ^/(.*)$ http://www.mydomain.com.au [R=301,NC,L]
0
Comment
Question by:JRockFL
2 Comments
 
LVL 13

Accepted Solution

by:
LinuxGuru earned 2000 total points
ID: 38786582
Try to use the following to redirect all request to www.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}$1 [R=301,L]

Open in new window


Cheers!!!
0
 
LVL 26

Expert Comment

by:arober11
ID: 38786622
For a start alter the pattern and conditions on your to rules to loose the leading / and the NC e.g.

RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule .* http://www.mydomain.com [R=301,L]

Open in new window


If still broke and assuming the rules above are in your httpd.conf  (not a .htaccess file), then stick a:

RewriteLog  /tmp/temp_rewrite_debug.log
RewriteLogLevel 9

in the same block and restart apache. Then tail the log, to see what's coming in, by way of a HTTP_HOST, and what the module makes of it.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question