homepage Welcome to WebmasterWorld Guest from 54.226.191.80
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

    
Rewrite rules in .htaccess preventing wordpress to work
AlexB77




msg:4530450
 4:03 pm on Dec 22, 2012 (gmt 0)

Hey All,

Just had this problem for the first time ever.

I have just installed WordPress in one of the folders on my root domain mydomain.com/blog/

Next discovered that some rewrite rules are preventing it from run on the domain.

I am on Apache with php5

the rules are as follows:

rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ [mydomain.com...] [r=301,nc]
rewritecond %{http_host} ^mydomain.biz [nc]
rewriterule ^(.*)$ [mydomain.com...] [r=301,nc]
rewritecond %{http_host} ^mydomain.co.uk [nc]
rewriterule ^(.*)$ [mydomain.com...] [r=301,nc]
rewritecond %{http_host} ^mydomain.info [nc]
rewriterule ^(.*)$ [mydomain.com...] [r=301,nc]
rewritecond %{http_host} ^mydomain.net [nc]
rewriterule ^(.*)$ [mydomain.com...] [r=301,nc]
rewritecond %{http_host} ^mydomain.org [nc]
rewriterule ^(.*)$ [mydomain.com...] [r=301,nc]
rewritecond %{http_host} ^mydomain.us [nc]
rewriterule ^(.*)$ [mydomain.com...] [r=301,nc]


Have now been stuck with this for over 5 hours, but cannot seem to find any answer anywhere.

Help Please!

Even coffee does not help any more :)

 

g1smd




msg:4530451
 4:10 pm on Dec 22, 2012 (gmt 0)

Please edit post to use example.com so that code is readable.

Escape literal periods in patterns.

Every rule needs the [L] flag.

AlexB77




msg:4530455
 4:39 pm on Dec 22, 2012 (gmt 0)

thanks for your speedy response and advise, I have tried it in the following way too:

rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com [L,R]
rewritecond %{http_host} ^example.biz [nc]
rewriterule ^(.*)$ http://www.example.com [L,R]
rewritecond %{http_host} ^example.co.uk [nc]
rewriterule ^(.*)$ http://www.example.com [L,R]
rewritecond %{http_host} ^example.info [nc]
rewriterule ^(.*)$ http://www.example.com [L,R]
rewritecond %{http_host} ^example.net [nc]
rewriterule ^(.*)$ http://www.example.com [L,R]
rewritecond %{http_host} ^example.org [nc]
rewriterule ^(.*)$ http://www.example.com [L,R]
rewritecond %{http_host} ^example.us [nc]
rewriterule ^(.*)$ http://www.example.com [L,R]


so as you can see I have tried it both ways, but yet still have no luck with accessing the wordpress admin panel nor that I can actually get to the example.com/blog/index.php, unless I've disabled .htaccess completely or at least deleted those rules.

AlexB77




msg:4530460
 6:01 pm on Dec 22, 2012 (gmt 0)

Never mind, I have discovered the problem, for those of you who will run in to the similar problem, first stem is to disable your .htaccess file (remember disable not delete), then log in to your wordpress dashboard got to settings and change both urls to the http://www.example.com/blog then save it and enable your .htaccess. at that point you should be good to go.

g1smd




msg:4530461
 6:08 pm on Dec 22, 2012 (gmt 0)

Escape the literal periods in patterns.

The R flag generates a 302 redirect unless you explicitly specify 301.

Your ruleset does nothing for requests beginning www.

AlexB77




msg:4530462
 6:24 pm on Dec 22, 2012 (gmt 0)

I have and instead used the following [r=301,nc]. So I think that this is the right way, would you agree?

g1smd




msg:4530463
 6:29 pm on Dec 22, 2012 (gmt 0)

Every rule must have the [L] flag. Every rule.

Escape the literal periods in patterns.

AlexB77




msg:4530465
 6:40 pm on Dec 22, 2012 (gmt 0)

I am sorry, I am not really clear on this one, can you please show the full example of how this should be done? Please, since this would probably also help many others

g1smd




msg:4530467
 6:48 pm on Dec 22, 2012 (gmt 0)

Usually something like this:

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


with one of those for each host name.


If you want to redirect all host name requests to one:

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


The one rule does everything.

AlexB77




msg:4530470
 6:58 pm on Dec 22, 2012 (gmt 0)

I get it, so you are basically suggesting to use the last 2 lines instead of using bunch of individual URL rewrite/redirect requests. I have actually just tried this on my site and seem to be doing the job and even redirecting all IP requests to www.myexample.com. Well I honestly did not know about this particular way, should probably read more about it.

So this is also prevents duplication I believe?

lucy24




msg:4530491
 12:00 am on Dec 23, 2012 (gmt 0)

I get it, so you are basically suggesting to use the last 2 lines instead of using bunch of individual URL rewrite/redirect requests.

Yes, exactly. That's assuming you own a string of domain names that all live in the same place (same server, or same userspace within shared hosting), and you want to redirect all of them to a single form.

You only have to say "is not the right form"

!^(www\.example\.com)?$

because if you don't control "example.info" "example.co.uk" or whatever, the request would never reach your htaccess in the first place.

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