Welcome to WebmasterWorld Guest from 54.161.181.156

Forum Moderators: Ocean10000 & incrediBILL & phranque

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

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

5+ Year Member



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.
10:02 pm on Jul 24, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Where in the .htaccess did you add it?

Rule order is very important. Your new redirect should go before any exisiting rewrites.
10:07 pm on Jul 24, 2012 (gmt 0)

5+ Year Member



That is the only thing in my .htaccess file. There's nothing else at all in there.
11:31 pm on Jul 24, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



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?
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
7:00 pm on Jul 25, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



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...
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
7:57 pm on Jul 26, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

Featured Threads

Hot Threads This Week

Hot Threads This Month