Welcome to WebmasterWorld Guest from 54.144.48.252

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Rewrite rules in .htaccess preventing wordpress to work

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

5+ Year Member



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 :)
4:10 pm on Dec 22, 2012 (gmt 0)

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



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

Escape literal periods in patterns.

Every rule needs the [L] flag.
4:39 pm on Dec 22, 2012 (gmt 0)

5+ Year Member



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.
6:01 pm on Dec 22, 2012 (gmt 0)

5+ Year Member



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.
6:08 pm on Dec 22, 2012 (gmt 0)

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



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.
6:24 pm on Dec 22, 2012 (gmt 0)

5+ Year Member



I have and instead used the following [r=301,nc]. So I think that this is the right way, would you agree?
6:29 pm on Dec 22, 2012 (gmt 0)

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



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

Escape the literal periods in patterns.
6:40 pm on Dec 22, 2012 (gmt 0)

5+ Year Member



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
6:48 pm on Dec 22, 2012 (gmt 0)

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



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.
6:58 pm on Dec 22, 2012 (gmt 0)

5+ Year Member



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?
12:00 am on Dec 23, 2012 (gmt 0)

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



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month