Mobile app version of vmapp.org
Login or Join
Ravi8258870

: How can I redirect old WordPress URL (with a query string) to new URL using .htaccess? I transferred my WordPress site to static HTML website, but some other website have a link to my old

@Ravi8258870

Posted in: #Htaccess #Redirects #Url

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 mysite.com/mypage.html

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Ravi8258870

1 Comments

Sorted by latest first Latest Oldest Best

 

@Megan663

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 mydomain.site/page/3 Redirect /page.php?id=4 mydomain.site/page/4
RedirectMatch ^/page.php?id=([0-9]*)$ mydomain.site/page/


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 ^(.*)$ 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 .* mydomain.site/mypage.html [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme