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
-
Should I canonicalize URLs with no query params even though query params are always automatically appended?
There's a section of my client's website that presents quarterly government financial data. Users can filter results to see different years and quarters of financial info. If a user navigates to those pages, the URLs automatically append the latest query parameters. It's not a redirect...when I asked a developer what the mechanism was for this happening, he said "magic." He honestly didn't know how to describe it. So my question is, is it ok to canonicalize the URL without any query parameters, knowing that the user will always be served a page that does have query parameters? I need to figure out how to manage all of the various versions of these URLs.
Technical SEO | | LeahH0 -
Set Up htaccess File
Looking for expert help (willing to pay) to set up a proper htaccess file. I'm having an issue as the site has a subdomain at secure.domain.com and has php extensions there. I tried a couple recommended code sets but it seems to be a mess. The site is working properly but this may be causing rankings issues. It's coded in pure HTML and PHP, no Wordpress stuff.
Technical SEO | | execubob
The delete www causes the secure side to fail. The delete html extensions causes the php extensions to fail.0 -
.htaccess Question
Hi,I have a website www.contractor-accounts.co.uk that has an .htaccess file that strips .php and forces a closing brace /. The site is now over 6 months old and still has a very low ranking with MOZ also rating the site as DA/PA = 1 which seems to indicate some sort of issue with the website. Can anyone offer any suggestions as to why this site is ranking poorly as much of the onpage SEO has been completed to a level of 90%+ for specific keyterms so I'm probably either looking at routing of the framework of so other technical SEO issues possibly? Any help much apreciated... <ifmodule mod_rewrite.c=""><ifmodule mod_negotiation.c="">Options -MultiViews</ifmodule> RewriteEngine On # Redirect Trailing Slashes...
Technical SEO | | ecrmeuro
# RewriteRule ^(.)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} /+[^.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
# Redirect non-WWW to WWW...
RewriteCond %{HTTP_HOST} ^contractor-accounts.co.uk [NC]
RewriteRule ^(.)$ http://www.contractor-accounts.co.uk/$1 [L,R=301] # Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]</ifmodule>0 -
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 -
Removing URL Parentheses in HTACCESS
Im reworking a website for a client, and their current URLs have parentheses. I'd like to get rid of these, but individual 301 redirects in htaccess is not practical, since the parentheses are located in many URLs. Does anyone know an HTACCESS rule that will simply remove URL parantheses as a 301 redirect?
Technical SEO | | JaredMumford0 -
Do I need a 301 redirect on htaccess if Apache is already configured to serve?
Apache is set up to serve both www and non-www versions the same content. Do I still need to put a 301 redirect in the htaccess file?
Technical SEO | | Ocularis0 -
How to avoid automated queries to Google
We have a search engine marketing team working on different projects and we share same IP. We check our rankings manually on Google, is it sending automated queries to Google? Can it affect our sites? What solution do you suggest to check rankings without sending multiple queries to Google?
Technical SEO | | koamit0 -
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