301 redirect rule
-
Hi there,
I have a website that has hundreds of links with a "question mark" at the end of URLs. For example:
http://www.domain.com/directory/page.html?
http://www.domain.com/directory/another-directory?
http://www.domain.com/directory/yet-another-directory/?I'm want to place a wildcard redirect on the .htaccess file but don't know what exactly to add. Ideally I want the URLs above to be:
http://www.domain.com/directory/page.html
http://www.domain.com/directory/another-directory/
http://www.domain.com/directory/yet-another-directory/Any help is most appreciated.
Thanks
Issa -
Hmmmm...you shouldn't need the RewriteCond. The regex for the rule itself merely needs to end in ?$, indicating that the ? must be the last character on the line.
And your rule looks to me like it will APPEND a question mark, not remove it!
I haven't tested this, but this should work as a blanket rule for all files and folders:
RewriteRule ^(.*)?$ /$1 [L,R=301]
-
Hi again,
Thank you for all this so far, however, it still doesn't help me very much. If i will need to follow the same system I will need to create a redirect line for each directory level and variation level I have on the website. Please not that in my initial question i said I have hundreds of cases of this issue.
I have discussed this issue with friends who came up with a solution that I thought i should share with you guys here. The redirect code should be:
RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)\ /[^\ ?]*?($|\ )
RewriteRule ^(.*)$ /$1? [L,R=301]
The first line ensures that the rule will only deal with question marks that appears at the end of the URL not the middle (as you kindly mentioned before). The second line then removes the question mark.
Plus, its just 2 lines, 1 rule which is a much shorter format
I hope this will be useful to someone else, it surely has saved me a lot of trouble, its now implemented and works perfectly.
Issa
-
Donford's correct. The "." matches any character; the "*" says 0 or more times; the $ means end of line.
-
the .*$ is the wildcard you can redirect on match keyword or directory.
Here is a good site that helps with this, special note the "Wildcard Redirect" section.
The question mark is usually an indication that the urls are dynamic if that is the case you may also want to review this helpful post on seOverflow.com about dynamic urls.
-
Not sure how the status of this question has changed to "Answered" but no thats not the right answer I'm afraid. What I was asking for is a wildcard redirect not redirect for the three examples i provided.
As mentioned i have hundreds of pages that require this change.
Issa
-
Donford's answer looks right to me, but I'd test it on your particular server as well.
My experience with .htaccess is that the various test tools don't always perform exactly the same as the server itself; also different webserver software (even different versions of Apache!) seem to have different results for the same patterns.
So...it's not always even sufficient to test on your development server.
-
This should work..
Test it out and see if we're on the right track.
RewriteEngine on
RedirectMatch 301 ^page.html?.$ http://www.domain.com/directory/page.html
RedirectMatch 301 ^/another-directory?.$ http://www.domain.com/directory/another-directory/
RedirectMatch 301 ^/yet-another-directory/?.*$ http://www.domain.com/directory/yet-another-directory/
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
-
Moving html site to wordpress and 301 redirect from index.htm to index.php or just www.example.com
I found page duplicate content when using Moz crawl tool, see below. http://www.example.com
Intermediate & Advanced SEO | | gozmoz
Page Authority 40
Linking Root Domains 31
External Link Count 138
Internal Link Count 18
Status Code 200
1 duplicate http://www.example.com/index.htm
Page Authority 19
Linking Root Domains 1
External Link Count 0
Internal Link Count 15
Status Code 200
1 duplicate I have recently transfered my old html site to wordpress.
To keep the urls the same I am using a plugin which appends .htm at the end of each page. My old site home page was index.htm. I have created index.htm in wordpress as well but now there is a conflict of duplicate content. I am using latest post as my home page which is index.php Question 1.
Should I also use redirect 301 im htaccess file to transfer index.htm page authority (19) to www.example.com If yes, do I use
Redirect 301 /index.htm http://www.example.com/index.php
or
Redirect 301 /index.htm http://www.example.com Question 2
Should I change my "Home" menu link to http://www.example.com instead of http://www.example.com/index.htm that would fix the duplicate content, as indx.htm does not exist anymore. Is there a better option? Thanks0 -
Redirecting an IP address
Just taken over a new client who recently moved from A.N. other platform to Shopify. I just found reference to their old website IP address and it appears to be not redirecting. Can I simply use something like Traffic Control (Shopify app) to redirect to the new domain?
Intermediate & Advanced SEO | | muzzmoz0 -
How to speed up transition towards new 301 redirected landing pages?
Hi SEO's, I have a question about moving local landing pages from many separate pages towards integrating them into a search results page. Currently we have many separate local pages (e.g. www.3dhubs.com/new-york). For both scalability and conversion reasons, we'll integrate our local pages into our search page (e.g. www.3dhubs.com/3d-print/Bangalore--India). **Implementation details: **To mitigate the risk of a sudden organic traffic drop, we're currently running a test on just 18 local pages (Bangalore) = 1 / 18). We applied a 301 redirect from the old URL's to the new URL's 3 weeks ago. Note: We didn't yet update the sitemap for this test (technical reasons) and will only do this once we 301 redirect all local pages. For the 18 test pages I manually told the crawlers to index them in webmaster tools. That should do I suppose. **Results so far: **The old url's of the 18 test cities are still generating > 99% of the traffic while the new pages are already indexed (see: https://www.google.nl/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=site:www.3dhubs.com/3d-print/&start=0). Overall organic traffic on test cities hasn't changed. Questions: 1. Will updating the sitemap for this test have a big impact? Google has already picked up the new URL's so that's not the issue. Furthermore, the 301 redirect on the old pages should tell Google to show the new page instead, right? 2. Is it normal that search impressions will slowly shift from the old page towards the new page? How long should I expect it to take before the new pages are consistently shown over the old pages in the SERPS?
Intermediate & Advanced SEO | | robdraaijer0 -
Have You 301 Redirected Domain A to Domain B ?
I only have two questions.... Approximately when did you do it (year is close enough)? Did the rankings of Domain B go up? Any other information that you care to share will be appreciated. Thank you!
Intermediate & Advanced SEO | | EGOL0 -
Php 301 redirect
Hi I am migrating an old wordpress site to a custom PHP site and the URL profiles will be different, so want to retain all link profiles and more importantly if a user visits the old urls via search then they are seamlessly transferred to the new equivalent page For example www.domain.com/about-us is going to need to redirect to www.domain.com/aboutus.php www.domain.com/furniture is going to need to redirect to www.domain.com/furniture-collections.php etc What is the best way of achieving this apart from .htaccess as not 100% confident of doing this. Could it be done via PHP or using meta tags?
Intermediate & Advanced SEO | | ocelot0 -
301 Redirected url to new subdomain, now the rank appears to be completely gone...
In an attempt to not feel bad for not blogging, I set up a new subdomain on my site to have a "coming soon" style page and "best of" section for my blog and video show properties. All the pages on the relaunch subdomain are done in Unbounce. http://relaunch.tommy.ismy.name The idea was that I would then take the pages on my regular domain, and one by one create landing pages that test out new design ideas (instead of going into full production web design) and redirect the traffic from the top ranked pages to the new, redesigned pages. At first, I set up the 301 through a plugin in wordpress and for the first week or so it was great. As far as I know, I did set my canonical tags up properly on that page too. However, just a couple days ago, I wasn't getting the same traffic, and my top ranked keyword that accounts for over half my traffic is nowhere to be found in at least the first 15 pages of search results. Which stinks, because I've maintained that rank for well over 2 years 😞 Clearly, something I did wasn't liked by Google, and I wonder, what did I do "wrong" and is there anything I could do to get that rank back?
Intermediate & Advanced SEO | | Thomas_m_walker0 -
Canonical or 301 redirect, that is the question?
So my site has duplicate content issues because of the index.html and the www and non www version of the site. What's the best way to deal with this without htaccess? Is it a 301 redirect or is it the canonical, or is it both?
Intermediate & Advanced SEO | | bronxpad0 -
Duplicate content even with 301 redirects
I know this isn't a developer forum but I figure someone will know the answer to this. My site is http://www.stadriemblems.com and I have a 301 redirect in my .htaccess file to redirect all non-www to www and it works great. But SEOmoz seems to think this doesn't apply to my blog, which is located at http://www.stadriemblems.com/blog It doesn't seem to make sense that I'd need to place code in every .htaccess file of every sub-folder. If I do, what code can I use? The weirdest part about this is that the redirecting works just fine; it's just SEOmoz's crawler that doesn't seem to be with the program here. Does this happen to you?
Intermediate & Advanced SEO | | UnderRugSwept0