Htaccess rewrites
-
We’re using wordpress, and we have the following in the .htaccess:
BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
END WordPress
We have a URL like http://subdomain.example.com/select-a-card/?q=fuel, and I want to rewrite it so that it becomes http://subdomain.example.com/fuel-card/
What do I need to add to the htaccess to do this??
Thanks,
-
I managed to strip out the '?q=' query with the htaccess below, but unfortunately this breaks the query. Any way around this?? (http://subdomain.example.com/select-a-card/?q=fuel)
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^q=fuel$
RewriteRule ^(.*)$ /fuel/? [R=301, L]BEGIN WordPress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]END WordPress
-
This should work:
RewriteRule ^([^/]*)/$ /select-a-card/?q=$1 [L]
This will redirect http://subdomain.example.com/select-a-card/?q=__anyname to http://subdomain.example.com/anyname__/. If you just want to 301 the one page, try this:
Redirect 301 /select-a-card/?q=fuel http://subdomain.example.com/fuel-card/
-
Ok, so how about if I make the ask a bit easier...
Whilst not an ideal solution, it would be good if I could just rewrite
http://subdomain.example.com/select-a-card/?q=fuel
to
http://subdomain.example.com/select-a-card/fuel/
...or ideally with a trailing slash too: http://subdomain.example.com/select-a-card/fuel/
-
No it wont be conflicting with WordPress, just a matter of getting the syntax correct. I'll try and amend my initial solution later this evening and report back, thanks in advance for your patience.
-
Hi Ben,
Thanks for replying. Unfortunately I've tried the above and it's not working.
I've tried escaping everything, but still no joy. Could this be clashing with wordpress permalink redirects perhaps?
-
Try this:
BEGIN WordPress
<ifmodule mod_rewrite.c="">RewriteEngine On
RewriteBase /
# Custom Rewrite Rules
RewriteCond %{REQUEST_URI} ^/select-a-card/$ [NC] RewriteCond %{QUERY_STRING} ^q=fuel$ RewriteRule ^index.php$ /fuel-card/? [R=301,NC,L]
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]</ifmodule>END WordPress
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
-
.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 -
High DA url rewrite to your url...would it increase the Ranking of a website?
Hi, my client use a recruiting management tool called njoyn.com. The url of his site look like: www.example.njoyn.com. Would it increase his ranking if I use this Url above that point to njoyn domain wich has a high DA, and rewrite it to his site www.example.com? If yes how? Thanks
Technical SEO | | bigrat950 -
Lowercase Rewrite in web.config. Strange behavior.
So I am trying to implement a lower case rule in my rewrite section and I am using the same snippet below that can be found all over the web. The lower casing of my url works fine but it adds my domain name into the URL for reasons I can't explain. so this www.SomeSite.com/Upper.aspx become www.somesite.com/somesite/upper.aspx I removed all other rewrite rules but this one and still it happens. Has anyone seen this? My server is IIS 7 <match url="[A-Z]" ignorecase="false"></match> <action type="Redirect" url="{ToLower:{URL}}"></action>
Technical SEO | | Banknotes0 -
Duplicate Page Titles Warnings, htaccess Rewrite & Canonical Links.
Hey guys, Just signed up for a pro account and I am getting Duplicate Page Title warnings on links that are duplicate, rewritten for SEO, but have a canonical href tag. I have two sets of links in my store: SEO friendly: http://www.mysite.com/item/iphone-case Operational link: http://www.mysite.com/shop/product.php?pid=11 This operational link however has a href canonical tag pointing to the SEO friendly link as being the primary link. My question is; Do I need to worry about this Duplicate Page Title Warning if I am using a canonical tag on the Operational link pointing to the SEO friendly link? Thanks!
Technical SEO | | jason3600 -
.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 -
Problem www/non-www domain rewrite
Hello, I've made a site for a client about 1 year ago. The rankings are quite okay, but the home page suffers from a penalty I think. I found out via OSE that PageAuthority strangely is higher on the 301-ed page www.myanmar-rundreisen.de - PA 32
Technical SEO | | hgw57
myanmar-rundreisen.de/ - PA 33 I don't understand what is happening here as I am using the usual htaccess 301-redirect: Rewrite domain.com -> www.domain.com RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.myanmar-rundreisen.de [NC]
RewriteRule (.*) http://www.myanmar-rundreisen.de/$1 [L,R=301] which is working fine with other domains ... I tried also (last line) RewriteRule (.*) http://www.myanmar-rundreisen.de/$1 [L,R=301] So thanks to anyone who can share an idea on that ... Guenter K04xy.jpg0 -
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 -
What are the impact of doing URL Rewriting instead of 301 redirections whille optimizing a blog?
In WordPress, with the ALL In ONE SEO pluggingm we've optimze the permalinks to show more keewords in the URL'. What can be the impact?
Technical SEO | | webit400