Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Trying to set 301 redirect in .htaccess file and here is what i am trying to do

RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
RewriteRule (.*)$ http://www.mysite.com/wordpress/$1 [R=301,L]

I am testing this on my local machine using WAMPP server.Though when i hit http://localhost/wordpress/ i am getting redirected to http://www.mysite.com/wordpress/ but for other URL i am not getting redirected at all.for e.g

i have this URL in my local machine http://localhost/wordpress/2010/11/shadows/ and this at the server http://www.mysite.com/wordpress/2010/11/shadows/ but when i hit this URL i am not getting redirected to respected URL on the live server ,but i am being showed same page from local machine

can any one tell me whats wrong with the redirection entry Thanks in advance

share|improve this question
I'm not sure that this is a WordPress-specific question... – Chip Bennett Feb 14 '12 at 17:09
@ChipBennett: seems to be agree with you since there is little wordpress is doing here, only relation is that i am using wodpress – Umesh Awasthi Feb 14 '12 at 17:13
Hmm... well then, unless you're experiencing some problems in the interaction with the WordPress-generated redirect rules, you would probably be better-off asking this question over at ServerFault. – Chip Bennett Feb 14 '12 at 17:19
@ChipBennett: Agree and i already realize that and asked the same (stack-exchange), but since the post has been answered i can not delete it – Umesh Awasthi Feb 14 '12 at 17:28

closed as off topic by Chip Bennett, toscho Mar 4 '12 at 16:07

Questions on WordPress Answers are expected to relate to WordPress within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

3 Answers

RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [NC,OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$ [NC]
RewriteRule (.*)$ http://mysite.com/wordpress/$1 [R=301,L]

This worked for me.

share|improve this answer
i tried that one before and crosschecked just now,its not working, still same results. – Umesh Awasthi Feb 14 '12 at 16:05
@umeshawasthi I updated my answer. I tested it and it worked for me. – Kyle Feb 14 '12 at 16:30
for me the above code is not working at all.its really strange.i am not sure if this has something to be with WAMPP server i am using – Umesh Awasthi Feb 14 '12 at 16:52

Based on http://wordpress.stackexchange.com/a/8670/7401 I just tried the following and it worked for me.

RewriteEngine on 
RewriteBase / 
RewriteRule ^(.*) http://mysite.com/$1 [R=301,L] 

I placed this in an .htaccess file in a subfolder of my local domain and it redirected requests to an online site....

(But I have a self-installed apache, mysql and php setup, ie. not WAMPP etc....)

share|improve this answer
seems something wrong with the WAMPP in my localmachine – Umesh Awasthi Feb 14 '12 at 17:04
on a curious note, which server your tried this as i am trying in on WAMPP – Umesh Awasthi Feb 14 '12 at 17:12
locally I'm using with apache 2.2.14 – Aces Feb 14 '12 at 17:19

Remove the $ endings from your Rewrite Conditions.

The $ = end-of-line in regular expressions. ^test$ will only match "test" not "testing".

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.