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
-
Does anyone know a way to restore data more than sixteen months old from GSC or extract more than 1000 queries.
Does anyone know a way to restore data more than sixteen months old from GSC or extract more than 1000 queries?
Technical SEO | | RossKernez0 -
Rel Canonical, Follow/No Follow in htaccess?
Very quick question, are rel canonical, follow/no follow tags, etc. written in the htaccess file?
Technical SEO | | moon-boots0 -
Site hit by algorthithmic update in October 2014 - filters and thin content queries.
Back in October 2014 last year, a site we are working with had a significant drop in organic traffic. This coincided with Google's algorithmic update. The side in question uses filters extensively and at the time did not have any canonical tags in place. The lions share of these filter pages had little or no written content just products. The website now has canonical tags throughout and content has started to be added to the top level categories and we will continue to add more, however there is still a large amount of pages with little or no content. Webmaster tools shows that there are large amounts of internal links (for instance 42,000+ to the homepage) which must be due to the filtered pages. I am looking for advice on what is the best way to proceed. Do I edit robots.txt, start adding no follow tags or something else entirely?
Technical SEO | | bfinternet0 -
RewriteQueryString and .htaccess usage
I'm trying to redirect a whole load of pages which use a query string to a different directory for example. Original URL: example.com/news/post.php?s=2011-01-28-some-text New URL: example.com/blog/post.php?s=2011-01-28-some-text My understanding is that because the url uses query strings I need to use a rewrite rather than the usual redirect 301 etc. I've come up with this but it is not doing the job. Any ideas what I'm doing wrong? RewriteEngine On
Technical SEO | | RodneyRiley
RewriteCond %{QUERY_STRING} s=
RewriteRule ^/news /blog [L,R=301]0 -
A query about internal linking. Have I got this right?
Hi Guys I think this sounds like a right noobie question, but I am amongst friends so here goes. So our website is an ecommerce site selling magazines. There are certain magazines, for example Vogue, where we sell the UK version, USA, italian, spanish, french etc there's basically 13 different Vogue magazines on our site. The more niche ones attract some good long tail traffic. However, the UK version is competitive and so requires some extra umph to get us a half descent rank. However, when you search "vogue magazine subscription" for example, it's our italian vogue which is listed first. When I looked into this, I found that we had linked out from our UK Vogue to Italian vogue. Could this have given the italian vogue a marginal boost, as it had the additional internal links? What I have now done is add to some, not all, of the variations something along the lines "you will find the UK Vogue magazine here" where "UK Vogue Magazine" is the anchor text. Is this the right thing to do? Will this identify that the UK Vogue page is the higher priority page, or the more important page? I was also going to add to a category page a "Top 10 Womens magazines" section, and link to Vogue from there. Am I barking up the right tree? Thanks Guys Paul
Technical SEO | | TheUniqueSEO0 -
Htaccess file
I need to redirect the web pages which do not exist to 404 error the task need to be done in htaccess file. I am using Linux server. the webpages I want to redirect is my domain name followed by question mark e.g. www.mydomain.com/?dfdds I am using the following snippet in my htaccess file, it redirect to bing.com so far, please tell me how to change the snippet so that it redirect to redirect to 404 error page. ========================== RewriteCond %{QUERY_STRING} . RewriteRule .* http://www.bing.com? [L,R]
Technical SEO | | semer0 -
.htaccess and error 404
Hi, I permit to contact the community again because you have good and quick answer ! Yesterday, I lost the file .htaccess on my server. Right now, only the home page is working and the other pages give me this message : Not Found The requested URL /freshadmin/user/login/ was not found on this server Could you help me please? Thanks
Technical SEO | | Probikeshop0 -
How to handle sitemap with pages using query strings?
Hi, I'm working to optimize a site that currently has about 5K pages listed in the sitemap. There are not in face this many pages. Part of the problem is that one of the pages is a tool where each sort and filter button produces a query string URL. It seems to me inefficient to have so many items listed that are all really the same page. Not to mention wanting to avoid any duplicate content or low quality issues. How have you found it best to handle this? Should I just noindex each of the links? Canonical links? Should I manually remove the pages from the sitemap? Should I continue as is? Thanks a ton for any input you have!
Technical SEO | | 5225Marketing0