Mobile app version of vmapp.org
Login or Join
Phylliss660

: Htaccess redirect a page with a query string hosted on a temporary IP address? I have a site that was temporarily set up as 111.222.333.444/~mysite because the real URL was not ready. 111.222.333.444/~mysite/?page_id=123

@Phylliss660

Posted in: #Htaccess #UrlRewriting

I have a site that was temporarily set up as 111.222.333.444/~mysite because the real URL was not ready. 111.222.333.444/~mysite/?page_id=123 was a valid page on that site. My site is live now. I no longer want or need to use 111.222.333.444/~mysite to access the site.

However Google has indexed a search for a term on page ?page_id=123 as 111.222.333.444/~mysite/?page_id=123. But ?page_id=123 no longer exists. It's now on a new page, and I want to redirect Google's link to example.com/newpage
The closest I have come to implemeting this redirect is:

RewriteCond %{HTTP_HOST} ^111222.333.444$ [NC]
RewriteCond %{QUERY_STRING} ^?page_id=123$ [NC]
RewriteRule ^~mysite/$ //www.example.com/newpage [R=301,NE,NC,L]


But this doesn't work, and gives me an internal server error.

I have also tried:

Redirect 301 /?page_id=195 /newpage


But that had no effect. Can anyone suggest how to do this? I don't have a problem redirecting single pages, but the temporary/alternate URL with the IP address is throwing me.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Phylliss660

1 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

The mod_alias documenation states in the top section that it doesn't support redirects based on query strings. You are not going to be able to get a Redirect 301 rule to work.

I see a couple problems with your rewrite rule:


You are missing a period (.) in your ip address rule.
The question mark (?) is not included in the query string so ? should not be part of your QUERY_STRING rule.
mod_rewrite doesn't support protocol relative redirect URLs. Your new URL can't start with //. You need to start it with or unless you do a bunch of fancy hocus pocus.


Also:


I don't think you need the no case ([NC]) flag, so I would omit it.
I don't think you need the no escape ([NE]) flag, so I would omit it.
If your new site doesn't use a page_id=123 query string at all, you could remove the requirement that it has to be on the IP address.
Similarly, I would omit the ~mysite part of the rule. Just base the redirect on the the query string, not on the folder it is in.


I would try this rule:

RewriteCond %{QUERY_STRING} ^page_id=123$
RewriteRule (.*) www.example.com/newpage? [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme