homepage Welcome to WebmasterWorld Guest from 54.205.99.71
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Using .htaccess to rewrite all pages to www. generates 404 error!
DigitalSky




msg:4478552
 9:30 pm on Jul 24, 2012 (gmt 0)

I'm encountering a very odd issue here.

The site I am working on is a Drupal site. I want to make all of the page URLs rewrite to www.mydomain.com instead of simply mydomain.com.

I am attempting to do this by adding this code to the .htaccess file..


Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]


That code works on every other site I have perfectly. It doesn't work on my current Drupal site however. Instead, when I add that code to the .htaccess file something odd happens...

The home page of the site does indeed redirect to www.mydomain.com, however, all of the other pages within the site (i.e. [mydomain.com...] generate a 404 Error page.

Once I remove the code all the pages work fine again.

Any idea what is going on here? I can't figure this out for the life of me and it's driving me crazy, especially since I'm usually pretty savvy when it comes to these sorts of things.

 

g1smd




msg:4478555
 10:02 pm on Jul 24, 2012 (gmt 0)

Where in the .htaccess did you add it?

Rule order is very important. Your new redirect should go before any exisiting rewrites.

DigitalSky




msg:4478557
 10:07 pm on Jul 24, 2012 (gmt 0)

That is the only thing in my .htaccess file. There's nothing else at all in there.

lucy24




msg:4478569
 11:31 pm on Jul 24, 2012 (gmt 0)

Then you've got another htaccess somewhere. Doesn't drupal come with a big fat htaccess of its own to handle built-in rewriting? Where is the one you created?

rlange




msg:4478643
 4:11 am on Jul 25, 2012 (gmt 0)

Your redirect is working, obviously, but you're probably getting 404 errors because whatever rewrite rules Drupal uses have gone missing. Dig up the default .htaccess file for your Drupal version and copy everything into your current .htaccess file (below your redirect rules).

-
Ryan

lucy24




msg:4478848
 7:00 pm on Jul 25, 2012 (gmt 0)

OP said:
Once I remove the code all the pages work fine again.

This implies that the original htaccess is unchanged and is sitting wherever it was all along. If it had been overwritten, deleting new material wouldn't bring the old stuff back. So you're looking at two htaccess files, new and old, in different directories.

If the only new material is a with/without www redirect, it should probably go in the middle of the original htaccess: after all existing redirects but before all rewrites.

Now, if this can be pinned down without quoting the entire content of that elusive other file...

rlange




msg:4479085
 1:56 pm on Jul 26, 2012 (gmt 0)

lucy24 wrote:
This implies that the original htaccess is unchanged and is sitting wherever it was all along. If it had been overwritten, deleting new material wouldn't bring the old stuff back. So you're looking at two htaccess files, new and old, in different directories.

Good point. Still, Apache should be applying directives within all .htaccess files it finds in the path to the requested resource.

Hmm...

--
Ryan

g1smd




msg:4479209
 7:57 pm on Jul 26, 2012 (gmt 0)

It does, but if they are applied in the wrong order chaos can ensue.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved