homepage Welcome to WebmasterWorld Guest from 54.196.18.51
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Probably a simple error in htaccess for WP
non www to www for wordpress
chewy




msg:4647763
 10:48 am on Feb 22, 2014 (gmt 0)

Hi, here's what's working:

AddHandler php-stable .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


When I try to do non-www to www redirect (I've tried this a few ways and each time I get a 500 error)

so this is what doesn't work:

AddHandler php-stable .php
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


Is my logic right? Can't I just add those 2 mysite redirects?

I've done this a bunch of times on other sites but can't seem to get it right here.

Any suggestions?

[edited by: phranque at 2:17 pm (utc) on Feb 22, 2014]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]

 

phranque




msg:4647815
 2:23 pm on Feb 22, 2014 (gmt 0)

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
...
</IfModule>
# END WordPress

you don't need the IfModule container - WP won't work without mod_rewrite.
you need the RewriteEngine On before your first mod_rewrite directive.

usually a 500 Internal Server Error will leave clues in the server error log file.

chewy




msg:4647819
 2:34 pm on Feb 22, 2014 (gmt 0)

running it inside the tags (at the bottom) does not work - you're saying that putting these 2 lines:

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

inside the tags should work?

will be checking this momentarily.

chewy




msg:4647820
 2:41 pm on Feb 22, 2014 (gmt 0)

not gonna work.

here's the error message:

>The page isn't redirecting properly

>Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

>This problem can sometimes be caused by disabling or refusing to accept cookies.

I'm thinking something else may be wrong.

lucy24




msg:4648184
 9:52 pm on Feb 22, 2014 (gmt 0)

You have to put all external redirects before any internal rewrites. Looks like you've done that-- at least in the original version of your posted code. But all RewriteRules also have to come after the (first) "RewriteEngine on" statement. The originally posted version doesn't do this.

:: detour to test site to make sure I'm not talking through my hat ::

A RewriteRule placed before "RewriteEngine on" won't cause an error; it simply won't execute. (The Apache docs themselves say it's a simple alternative to commenting-out all your lines.)

The <IfModule> envelope doesn't matter. It isn't like <FilesMatch>, where the contents of the envelope execute in a separate loop after everything else.

>Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

Now, wait, so which is it? A 500 error or a message from the browser? They're entirely different things. Are you sure you haven't got a second with/without www. redirect-- in the opposite direction-- coded somewhere else in the same htaccess?

not2easy




msg:4648186
 10:04 pm on Feb 22, 2014 (gmt 0)

It is set inside WP settings. If it isn't www. in there, it can't redirect. It isn't necessary to add it to .htaccess, it will go to www if you have set the domain correctly in WP settings.

chewy




msg:4648246
 3:00 am on Feb 23, 2014 (gmt 0)

WP settings do not allow for modification without creating infinite looping type problems.

I'm thinking there very well may be other problems here.

This site was transferred over from another domain and I suspect something was hard coded as a result of that.

I'll check a few more things.

Thanks everybody.

lucy24




msg:4648258
 5:02 am on Feb 23, 2014 (gmt 0)

It isn't necessary to add it to .htaccess

Everything is htaccess. The only question is whether you wrote it yourself, or let the CMS (here WordPress) do it based on information you gave them.

WP settings do not allow for modification without creating infinite looping type problems.

That's an exaggeration, surely. Modifying an htaccess when you have a CMS in place is harder, because you have to work with what's already there. But the mere act of using a CMS doesn't bar you from ever editing your own htaccess.

g1smd




msg:4648279
 10:55 am on Feb 23, 2014 (gmt 0)

Make sure the WordPress hostname settings are right.

Delete the ifModule tags.

RewriteEngine On goes first followed by the canonical hostname redirect followed by the internal rewrite.

chewy




msg:4648296
 12:21 pm on Feb 23, 2014 (gmt 0)

So I'm getting closer.

Error is not a 500.

It is multiple 301's bouncing back and forth between www and non-www.

So there has to be at least one other redirect at play.

Settings are "greyed out" in the WP control panel Settings >> General Settings >> Wordpress Address (URL) and Site Adddress (URL).

Plus it shows the non-www address there, and attempts to edit the actual WP-Config file are also causing the same 301 www - non-www looping problems.

That's why I'm trying to figure out how to do a hard redirect.

Unfortunately, all attempts to get the WP General Settings to be editable have not worked out and working with the htaccess file is the temporary workaround until we sort that out.

Or not.

g1smd




msg:4648317
 2:37 pm on Feb 23, 2014 (gmt 0)

WordPress is redirecting to non-www.

Apache is redirecting to www.

There's your infinite loop.

chewy




msg:4648322
 3:39 pm on Feb 23, 2014 (gmt 0)

Oh yeah, for sure.

Confirmed at the highest level by the wizards at the host and now confirmed by you all (wizards all!)

Now to figure out the simplest solution over on the WP side.

All other solutions have also failed.

Fortunately, I have some time before launch.

Thanks for helping to eliminate various options.

chewy




msg:4648764
 1:18 am on Feb 25, 2014 (gmt 0)

Yep - we got it solved. Perfect!

The problem resulted from installing this particular version of the site with BackupBuddy and the URL was chosen wrong in setting things up, which created hard coded paths to the non-www version for every page.

Installation of WPMU Infinite SEO plugin somehow resolved things at high enough level that we were able to revise the wp-config file without creating any problems and voila!

Truthfully, your help was invaluable.

It proved we needed to look elsewhere.

And in less than 20 minutes today, all is now working like it is supposed to.

Thanks again.

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