Htaccess query
-
I'm currently working on a live version of a clients website which has duplication issues. With .htaccess, I need to rewrite URL's of the following format:
vacancy.php?id=802 to vacancy/?id=802
I tried adding the following line but it returned a 500, and don't want to keep taking the site out.
RewriteRule ^vacancy/?id=([0-9]+)$ vacancy.php?id=$1 [R=301, L]
-
Hi again Matt,
Actually, you don't need to be using the 301 at all. A simple rewrite will do what you are wanting.
If you do it like this:
RewriteRule ^vacancy/([0-9]+)$ vacancy.php?id=$1 [L]
your URLs would be a lot more friendly.
The resultant URLs would look like this:
/vacancy/12345
Hope that helps,
Sha
-
Hi Matt,
The 500 Error is caused by the "space" in [R=301, L]
Should be [R=301,L]
Hope that helps,
Sha
-
Hi,
please back up your .htaccess before attempting
Redirect match might work, but only if you are redirecting all to one - Keep in mind the initial directive needs to be changed to your specific scenario, as well as the destination URL
RedirectMatch 301 ^page.php?id=(.*).htm$ http://www.example.com/content/$1.html
Or you could do it one by one -
RewriteCond %{QUERY_STRING} ^id=1$
RewriteRule ^page.php$ http://www.example.com/content/page? [R=301,L]Or here is a link to a resource (I HAVE NOT TESTED OR USED) but gets lots of good feedback, for helping you make easier work out of hundreds of dynamic redirects
http://www.mbstrategic.com/02/301-redirects-for-dynamic-urls-to-static-pages-with-htaccess/
Hope this helps
PS after a seconf look, your initial attempt might work, you just need a condition which would be similar to
RewriteCond %{QUERY_STRING} ^id=1$
-
Sorry, I should have been more clear. There are hundreds of vacancy ID's which change over time, so I need to use a rewrite rule to handle all cases now and in the future.
-
Here's the format you may need to follow, I'm not 100% positive this will work for you but I know this is how 301s are setup:
redirect 301 vacancy.php?id=802 **yourdomain.com/path-to-location/**vacancy/?id=802
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
-
Strange Behavior - Dupe Content Via Query String URLs?
Hey y'all, could use community help with some strange behavior I'm seeing with a particular ranking. A week ago a high volume keyword ranking above the fold dropped off the map. I immediately thought must be an algorithmic penguin penalty (no manual action message) or panda / dupe content issue. I think it's dupe content at this point because I found my former ranking page in the omitted results section for the keyword we used to rank for. The strange thing is that without making any changes, Google would momentarily show our domain ranking high page one again, but with a strange query string URL. At first just domain.com/page/? whereas the old ranking was held by domain.com/page/ but now I see several long query string URLs floating around that the engines don't seem to know what to do with. Canonical tags are in place to canonicalize any query string URL back to the top and I have now designated query string URLs as unimportant in Search Console parameter filtering but these URLs persist. I ended up deduplicating content to a page on another domain we own (think that was the original problem) and there seemed to be a positive effect but now we are top of page 2 with a much longer query string URL as the ranking page. It seems Google wants to rank everything but the former ranking URL even though it's the most authoritative by far, has canonical signals in place, and is now no longer duplicate content. Content checker tool showed 60% similarity to the other piece, which is a ratio I've never known to cause dupe content. We found the source of the query string URLs to be from an external site that has a link to us but it's a buggy site so filtering on the page adds the string to our URL, so Google can find them and thinks they're significant. Long question short, has anyone had trouble like this? Getting weird parameter / query URLs to get out of the index in favor of the non-parameter folder? Is it possible the main folder page got hit with Penguin and is "banned?" Still, I don't know why Google would go out of it's way to rank query string copy pages in its place if that were the case. Any help greatly appreciated. An example of the URL looks like this:
Technical SEO | | Alder
domain.com/page/?CustomerSubscriptionTrack1PageSize=1&CustomerSubscriptionTrack1Order=Sorter_ID&CustomerSubscriptionTrack1Dir=ASC&CustomerSubscriptionTrack1Page=3&WorkOrder_TBLOrder=Sorter_AssetID&WorkOrder_TBLDir=ASC&ID=1060 -
Simple duplicate content query
Hello Community, One of my clients runs a job board website. They are having some new framework installed which will lead to them having to delete all their jobs and re-add them. The same jobs will be re-posted but with a different reference number which in turn with change each URL. I believe this will cause significant duplicate content issues, I just thought I would get a second opinion on best practice for approaching a situation like this. Would a possible solution be to delete jobs gradually and 301 re-direct old URLs to new URLs? Many thanks in advance, Adam
Technical SEO | | SO_UK0 -
.htaccess code
I've got a .htaccess file set up on a site to redirect specific old pages to specific new pages on a different site: eg Redirect 301 /oldpage.html https://www.newsite.co.uk/newpage.html Redirect 301 /oldpage2.html https://www.newsite.co.uk/folder/ I have two questions: 1. Is that all the file needs? Or does it need any "rewrite engine on" type code? 2. I would also like to include code to "mop up" any other URLs and redirect them to the root, so that /anyotherpage.html redirects to newsite.co.uk Is there a way to do this?
Technical SEO | | abisti20 -
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 -
Redirection in .htaccess
Hi All, The problem is with the .htaccess file I have written 301 redirection code for Apache server but once I upload .htaccess file from ftp the website is throwing 500 error. Please help as I'm new to the redirection files.
Technical SEO | | Bharath_ATZ0 -
.htaccess redirects
I've done some research but can't find a good answer to this question. Here's my situation: Site redirects from example.com to www.example.com just fine. However, it doesn't work so well for internal pages. My site incorrectly redirects (non-www) example.com/page2 to www.example.com when it should instead go to www.example.com/page2 So I need a method to redirect non-www internal pages to www versions. Currently I have this in my .htaccess - do I need to modify the rules? RewriteEngine on
Technical SEO | | 3plains
RewriteCond %{HTTP_HOST} !^www.example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L] Thanks0 -
Canonical solution for query strings?
Greetings, The Hotel company where I'm employed uses query strings in it's url's to track customers. The query strings are integrated into our property management system, and they help identify who we need to pay commissions to, so they aren't going anywhere. While I understand that session variables could have been a better solution, I sort of inherited this problem. The issue I'm running into is that my Webmaster tools picks up these query strings as actual url's. So for instance: www.url.com/index.php?P_SOURCE=WBFQ Seems like a duplicate page of my root, and like wise for all my other pages that use our booking widget. So, Is there a canonical solution to this issue? or would 301/302's be the only solution. Also, we may have 10 different but specific query strings to put into our urls. Would the 301/302 approach cause any server issues for say 10 pages? So 10 pages x 10 access codes = a lot of redirects. Thanks in advance, Cyril
Technical SEO | | Nola5040 -
My .htaccess has changed, what do i do to avoid it again...?
Hello Today i notice that our site did not auto changed from without www to with, when i checked the .htaccess file i notice # in-front of each line and i know we did not insert it in there, after i removed it it worked fine. The only changes that we did recently was to a mobile version to the site but the call to autodirect is in a JS and not in the .htaccess, could it be the server..? is there any way that anything else might cause this...? The site is HTML and WP could it be because of that...? Thank's Simo
Technical SEO | | Yonnir0