mod_rewrite with non-www to www for all deep links
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
mod_rewrite with non-www to www for all deep links
I am still struggling to get non-www to www.
At the moment I have following code to redirect from non-www to www.
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
It works totally fine for home page but not for other deep links, such as http://domain.com/city/Sydney.php, they are still going to non-www pages. What 's the best approach I could use to solve it?
Thanks in advance
Last edited by colucix; 01-30-2012 at 11:13 PM.
Reason: Removed commercial link
Hi bathory
Good to see u again. Yep I did remove ^ and $ like you suggested, no function was changed and still working as before, still redirecting non-www home page to www. but other pages still not working. I dont think it was cache, I cleared and even tested with other browser that I never used before. If you type in google as "site:domain.com" , all the non-www pages will come up and try going to one of the the page if it makes any different to you.
Strange, it should work either way. Try the apache examples to see if you get lucky.
You can enable rewrite logging and check where the RewriteCond fails
I got it working now. I got another .htaccess in city folder, which has following,
RewriteEngine on
RewriteRule ^([^/\.]+)$ $1.php
to redirect any file with or without .php to filename.php. Somehow it was stuffing it up. so I removed city/.htaccess and work fine.
Thanks again for your help .. I will read the apache examples again to get better understand of it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.