.htaccess yikes!
-
Hi guys,
Having a bit of trouble getting a htaccess redirect working. It's very easy but I am making a small typo somewhere!
I want to redirect about 400 product pages located at;
http://domain.com/product/product-name
to
http://domain.com/product-name
..basically just dropping /product/
Any help would be appreciated as my errors in Moz are all over the place!
-
No problem - that's what this community is all about
-
Looks the good, thanks for all your help.
-
mod_rewrite and RedirectMatch are two different ways of doing a 301 redirect - both are fine. You can have both inside a htaccess file, however you may want to place the RedirectMatch directive outside of the call for the mod_rewrite module so after
-
Thanks for this, appears to work fine!
Is it ok sitting at the end?
BEGIN WordPress
<ifmodule mod_rewrite.c="">RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RedirectMatch 301 ^/product/(.*)$ http://cdkeyprices.com/$1</ifmodule>END WordPress
#php_flag display_startup_errors on
#php_flag display_errors on
#php_flag html_errors on
#php_value docref_root 0
#php_value docref_ext 0 -
You could use the following RedirectMatch directive in your htaccess file obviously swapping in your actual domain -
RedirectMatch 301 ^/product/(.*)$ http://www.domain.com/$1
-
I'm sure you don't want to rewrite all the pages 1 at a time, try the following to rewrite the entire folder.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.)product
RewriteRule ^(.)$ product/$1 [L] -
Hello MrPenguin,
Your code should look similar to this:
Redirect 301 /product/product-name http://domain.com/product-name
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
-
301 redirect syntax for htaccess
I'm working on some htaccess redirects for a few stray pages and have come across a few different varieties of 301s that are confusing me a bit....Most sources suggest: Redirect 301 /pageA.html http://www.site.com/pageB.html or using some combination of: RewriteRule + RewriteCond + RegEx I've also found examples of: RedirectPermanent /pageA.html http://www.site.com/pageB.html I'm confused because our current htaccess file has quite a few (working) redirects that look like this: Redirect permanent /pageA.html http://www.site.com/pageB.html This syntax seems to work, but I'm yet to find another Redirect permanent in the wild, only examples of Redirect 301 or RedirectPermanent Is there any difference between these? Would I benefit at all from replacing Redirect permanent with Redirect 301?
Technical SEO | | SamKlep1 -
.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 -
What's Worse - 404 errors or a huge .htaccess file
We have changed our site architecture pretty significantly and now have many fewer pages (albeit with more robust content and focused linking). My question is, what should I do about all the 404 errors (keep in mind, I am only finding these in Bing Webmaster tools, not Moz or GWT)? Is it worse to have all those 404 errors (hundreds), or to have a massive htaccess file for pages that are only getting hits by the Bing crawlbot. Any insight would be great. Thanks
Technical SEO | | CleanEdisonInc0 -
301 redirects without .htaccess
I have a client that recently moved from an old ZenCart e-commerce site to Volusion. The domain name did not change. We need to redirect a bunch of the old URLs; however, Volusion's redirect tool does not work for URLS with "?" . The old ZenCart structure is: http://www.mydomain.com/index.php?main_page=product_info&products_id=563 Volusion is a hosted platform and we do not have access to the .htaccess file. Any suggestions on a workaround? Thanks!Nancy <colgroup><col width="960"></colgroup>
Technical SEO | | NancyVPS
| |0 -
Htaccess code to 301 redirect a folder change
Hi, I need some help to redirect all my site as there was a folder change. eg, the old structure was www.mysite.com/stuff-1/bags.html and I need it to go to the same structure without the "-1" eg: /stuff/bags.html
Technical SEO | | Paul_MC
The "bags.html" will be lots of different products, so this would be a wildcard? What would the htaccess code need to be? Thanks0 -
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 -
Mod Rewrite / .htaccess avoid duplicate content
I have been searching and testing for hours but cannot find a solution. I am able to get a URL to display with out the file exntension. i.e domain.com/file instead of domain.com/file.php The problem is both versions of the URL above work, therefore a duplicate content issue. How can I force the URL with the file extension not to resolve and give a 404 error? Or just redirect to the non extension URL? IF it helps here is my code. Options +FollowSymLinks
Technical SEO | | MiamiWebCompany
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]0 -
Htaccess 301s to 3 different sites
Hi, I'm an htaccess newbie, and I have to redirect and split traffic to three new domains from site A. The original home page has most of the inbound links so I've set up a 301 that goes to site B, the new corporate domain. Options +FollowSymLinks
Technical SEO | | ellenru
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L] Brand websites C and D need 301s for their folders in site A but I have no idea how to write that in relationship to the first redirect, which really is about the home page, contact and only a few other pages. The urls are duplicates except for the new domain names. They're all on Linux..Site A is about 150 pages, should I write it by page, or can I do some kind of catch all (the first 301) plus the two folders? I'd really appreciate any insight you have and especially if you can show me how to write it. Thanks 🙂0