Htaccess redirect with question mark
-
Hi I have a problem setting up my htaccess for a specific page that has a question mark in the link, and one that has a space in the link and also a question mark. So I would like 2 redirects in my htaccess like that:
www.olddomain.com/page.php?page=pagename1
to
www.newdomain.com/newpage1.html
www.olddomain.com/page.php?page=page name2
to
www.newdomain.com/newpage2.html
I have tried with something like this but doesn't work:
RewriteEngine on
RewriteRule ^page.php?page=pagename1 "http://www.newdomain.com/newpage1.html" [R=301,L]
RewriteRule ^page.php?page=page name2 "http://www.newdomain.com/newpage2.html" [R=301,L]
Could someone tell me what exactly I have to change?
Thanks
-
Hi kyle thanks for the answer, I have tried with this code:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=13$
RewriteRule ^/page.php$ http://www.example.com/newname.htm? [L,R=301]But it doesn't work. Is it possible that it requires page.php?id=13 to exist? I don't have anymore the file on the server... Trying to reach page.php?id=13 it responds with a 404 error.
Any solutions?
-
Check out this page, about half way down in the article: http://www.tamingthebeast.net/articles3/spiders-301-redirect.htm
They cover both dynamic query pages and pages with spaces.
Good luck - kyle
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Redirect Chain Issue
I just found I'm having a redirect chain issue for http://ifixappliancesla.com (301 Moved Permanently). According to Moz, "Your page is redirecting to a page that is redirecting to a page that is redirecting to a page... and so on" These are the pages involved: 301 Moved Permanently
Technical SEO | | VELV
http://ifixappliancesla.com
https://ifixappliancesla.com https://www.ifixappliancesla.com/ This is what Yoast support told me: "The redirect adds the https and then the www, ending at: https://www.ifixappliancesla.com/. You want all variants of your site's domain to end up at: https://www.ifixappliancesla.com/ " - which is totally true. But I would also like not to have the redirect chain issue! Could you please give me an advise on how to properly redirect my pages so I don't have that issue anymore?0 -
Htaccess redirects
Annoyingly it's time to play with this beast again. I've been given the task of doing the following. Keeping the homepage live Redirecting categories to the specific categories on the new site Catch all redirects Now i've managed to setup the specific categories and the catch all redirects, however I am unsure how to keep the homepage live (which is like this:www.domain.com/ so I can't just exclude that?) Would appreciate any help.
Technical SEO | | ThomasHarvey0 -
Curious Keyword Tags Question...
In 2012, we got hit with something... I have always assumed Panda... We have hundreds of thousands of products on our site. Prior to the traffic drop, our old site design listed a small number of keywords tags on the product pages. About 10 or so... After the site re-design, we allowed all of the keyword tags to appear on these product pages and also linked them to our search results pages. I know that one thing this did is cause a lot of these Search Results pages to be indexed. But our traffic has been constantly declining since then... I wonder what would happen if I just went back to the old with a smaller number of keywords listed and not linked? Any thoughts? Thanks! Craig
Technical SEO | | TheCraig0 -
301 redirect and search engines
How long until 301 redirects get recognized by search engines? I noticed my link on Google isn't forwarding over to my new domain even after the 301 redirect. If I go to the site directly, the 301 redirect works. Anyone know how long it takes for search engines to pick it up? Thanks!
Technical SEO | | timeintopixels0 -
.htaccess help please
Hi there, Can anyone let me know what I need to add to my .htaccess file to make sure that the trailing slash on my domain gets redirected to my main domain name. For example, at the moment Google is seeing my primary domain as follows: http://www.mydomain.com http://www.mydomain.com/ I thought I'd covered off all possible duplication penalities but it look as though I've still got one left! Thanks very much for your help, Simon
Technical SEO | | theshortstack0 -
301 Redirect Domain or 301 Redirect Domain + Interior Pages
Hello - My company acquired another company in our industry and our IT team immediately set up the acquired companies domain name as a an alias to our site. This created a duplicate version of our website under another domain name and Google started ranking interior pages from the aliased acquired site for several top keywords that were previously held by our real site. Should we 301 redirect just the top level domain name of the acquired site to the real site or 301 redirect the top level domain name and the interior pages on the acquired site to help ensure that our real domain will take back the rankings it once had? Thanks!
Technical SEO | | Room2140 -
Google Webmaster redirect vs 301 redirect
OK assuming a client's website has the right tracking script (hopefully analytics isn't effected by this issue), ... what happens if the htaccess file has a 301 redirect to the www-address, but within Google Webmaster Tools, the address chosen to crawl by Google is the non-www address? How will Google handle and which address takes precedence in this situation? _Cindy
Technical SEO | | CeCeBar0 -
Query String Redirection
In PHP, I'm wanting to store a session variable based upon a link that's clicked. I'm wanting to avoid query strings on pages that have content. My current workaround is to have a link with query strings to a php file that does nothing but snags the variables via $_GET, stores them into $_SESSION, and then redirects. For example, consider this script, that I have set up to force to a mobile version. Accessed via something like a href="forcemobile.php?url=(the current filename)" session_start(); //Location of vertstudios file on your localhost. Include trailing slash $loc = "http://localhost/web/vertstudios/"; //If GET variable not defined, this page is being accessed directly. //In that case, force to 404 page. Same case for if mobile session variable //not defined. if(!(isset($_GET["url"]) && isset($_SESSION["mobile"]))){ header("Location: http://www.vertstudios.com/404.php"); exit(); } //Snag the URL $url = $_GET["url"]; //Set the mobile session to true, and redirect to specified URL $_SESSION["mobile"] = true;header("Location: " . $loc . $url); ?> Will this circumvent the issue caused by using query strings?
Technical SEO | | JoeQuery0