4

I transferred my WordPress site to static HTML website, but some other website have a link to my old WordPress site mysite.com/?page_id=1103.

I want to redirect all traffic to new URL which is mysite.com/mypage.html, but my redirect in .htaccess file doesn't work. Maybe someone can help me with the line of code in .htaccess file. I tried following but it didn't work:

Redirect 301 /?page_id=1103 http://mysite.com/mypage.html

1 Answer 1

3

Here is an article that answers your question:

Unfortunately, neither Redirect nor RedirectMatch allow you to specify a query string for the redirect source. It other words, the following statements are invalid and they will simply be ignored.

Redirect /page.php?id=3  http://mydomain.site/page/3
Redirect /page.php?id=4  http://mydomain.site/page/4

RedirectMatch ^/page.php?id=([0-9]*)$  http://mydomain.site/page/$1

The solution requires to change the focus from mod_alias to mod_rewrite. Here’s an example.

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/page\.php$
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^(.*)$ http://mydomain.site/page/%1.pdf [R=302,L]

So in your case the code should be:

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/$
RewriteCond %{QUERY_STRING} ^page_id=1103$
RewriteRule .* http://mydomain.site/mypage.html [R=301,L]
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.