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
-
How handle pages with "read more" text query strings?
My site has hundreds of keyword content landing pages that contain one or two sections of "read more" text that work by calling the page and changing a ChangeReadMore variable. This causes the page to currently get indexed 5 times (see examples below plus two more with anchor tag set to #sectionReadMore2 This causes Google to include the first version of the page which is the canonical version and exclude the other 4 versions of the page. Google search console says my site has 4.93K valid pages and 13.8K excluded pages. My questions are: 1. Does having a lot of excluded pages which are all copies of included pages hurt my domain authority or otherwise hurt my SEO efforts? 2. Should I add a rel="nofollow" attribute to the read more link? If I do this will Google reduce the number of excluded pages? 3. Should I instead add logic so the canonical tag displays the exact URL each time the page re-displays in another readmore mode? I assume this would increase my "included pages" and decrease the number of "excluded pages". Would this somehow help my SEO efforts? EXAMPLE LINKS https://www.tpxonline.com/Marketplace/Used-AB-Dick-Presses-For-Sale.asp https://www.tpxonline.com/Marketplace/Used-AB-Dick-Presses-For-Sale.asp?ChangeReadMore=More#sectionReadMore1 https://www.tpxonline.com/Marketplace/Used-AB-Dick-Presses-For-Sale.asp?ChangeReadMore=Less#sectionReadMore1
Technical SEO | | DougHartline0 -
Robots User-agent Query
Am I correct in saying that the allow/disallow is only applied to msnbot_mobile? mobile robots file User-agent: Googlebot-Mobile User-agent: YahooSeeker/M1A1-R2D2 User-agent: MSNBOT_Mobile Allow: / Disallow: /1 Disallow: /2/ Disallow: /3 Disallow: /4/
Technical SEO | | ThomasHarvey1 -
Pointing a sub-domain to a sub-folder in htaccess
I have a client who currently uses shopify for there blog. I want to set them up with a separate blog away from the shopify system and host it in Australia. I know the best option is using a subfolder but as the shopify system is an unmoveable CMS can I somehow point my subdomain to a subfolder and get the benefits of the domain name? I could do this by using the rewrite rule in the htaccess file. If I was to do this would it end up cloaking the URL's of the articles?
Technical SEO | | acs1110 -
.htaccess: Multiple URLs catches filename
Hi, I have the following line in my .htaccess:
Technical SEO | | rasmusbang
RewriteRule privacy stdpage.php?slug=privacy [L] So if you go to the www.mysite.com/privacy it takes the stdpage.php with the argument above. But if you go to www.mysite.com/privacysssssssss catches the same file. How can I prevent this? It will give me multiple URLs with the exact same content. I have a 404 page which i would like to show instead when the match is not 100%. -Rasmus0 -
How should I properly setup my .htaccess file?
I have searched google for 'how to setup .htaccess file' and it seems that every website has some variation. For example: RewriteCond %{HTTP_HOST} ^yoursite.com RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=permanent,L] On SEOMOZ someone posted this: RewriteCond %{HTTP_HOST} !^www.yoursite.com [NC] RewriteRule (.*) http://www.yoursite.com/$1 [L,R=301] On yet another website, I found this: RewriteEngine On RewriteCond %{HTTP_HOST} !^your-site.com$ [NC] RewriteRule ^(.*)$ http://your-site.com/$1 [L,R=301] As you can see there are slight differences. Which one do I use? I'm on Apache CentOS and I have HTML5 websites and several Joomla! wesites. Would the HTACCESS File be different for both?
Technical SEO | | maxduveen0 -
Htaccess redirects how many can i have and does it slow site down
I have had to redesign my site this year www.in2town.co.uk because my hosting company made a huge mistake while trying to update the joomla on my site which resulted in me losing thousands of pages and links. What i would like to know is, i have put some of the old urls in my htaccess file but i would like to know how many old urls i can have in my htaccess file as i am unsure how to use it properly. my idea was, to have some of the lost url links to my site and put them in my htaccess file and have them pointing to similar pages. not sure if this is a good idea or not. i think i have lost a few hundred good links but i would like to know if these urls in the htaccess file would slow down my joomla site any advice would be great.
Technical SEO | | ClaireH-1848860 -
.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 -
Non-www to www code not working in htaccess
I use the same rewrite code on every site to consolidate the non-www and www versions. All sites in Joomla, linux hosting. Code is as follows: RewriteEngine On rewritecond %{http_host} ^site.com/ rewriteRule ^(.*) http://www.site.com/$1 [R=301,L] Immediately following this code, I also rewrite /index.php to /. Thing is, I can get index.php to rewrite correctly but the non-www won't rewrite to www. I use the same code on every site but for some reason it's not working here. Are there common issues that interfere with rewriting a non-www to www in htaccess that could be interfering with the code I'm using above?
Technical SEO | | Caleone0