.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
-
Htaccess file help
Hi, thanks for looking i am trying (and failing) to write a htaccess for the following scenario <colgroup><col width="679"></colgroup> http://www.gardening-services-edinburgh.com/index.html http://www.gardening-services-edinburgh.com http://www.gardening-services-edinburgh.com/ | so that all of these destinations goto the one resource any ideas? thanks andy
Technical SEO | | McSEO0 -
Blogger /blog Folder level redirect setup using .htaccess
We have a blog currently powered by the free blogger.com website. We have set it up as blog.example.com we wish to seti it up as example.com/blog how can we do this using .htaccess file? we understand how to update htacess, but we don't know what code we should enter to achieve what we want our website is hosted on Apache servers with plesk control panel
Technical SEO | | Direct_Ram0 -
Htaccess mod rewrite from server address
Hi there, I'm not massively experienced with creating mod rewrite rules and I'm worried I've got this wrong as its slightly different to what I'm used to. The web dev and content creators were working on http://5.10.105.45/~isea/ to create content. I want to redirect all URL's to www.iseasurfwear.co.uk. This is what I've written //Rewrite to www
Technical SEO | | BlueTree_Sean
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^5.10.105.45/~isea/[nc]
RewriteRule ^(.*)$ http://www.iseasurfwear.co.uk/$1 [r=301,nc] Can anyone tell me if this is correct?0 -
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 -
Https and 404 code that goes into htaccess
The 404 error code we put into htaccess files for our websites does not work correctly for our https site. We recently changed one of our http sites to https. When we went to create a 404.html page for it by creating an htaccess folder with the 404 error code in it, once we uploaded the file all of our webpages were displaying incorrectly, as if the css was not attached. The 404 code we used works successfully for our other 404.html pages for our other sites (www.telfordinc.com/404.html). However, it does not work for the https site. Below is the 404 error code we are using for our https site (currently not uploaded until pages display correctly) ErrorDocument 404 /404-error.html RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www.)?privatemoneyhardmoneyloan.com/.*$ [NC] RewriteRule .(gif|jpg|js|css)$ - [F] Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www.privatemoneyhardmoneyloan.com$ [NC] RewriteRule ^(.*)$ http://www.privatemoneyhardmoneyloan.com/$1 [R=301,L] So we want to know if there is a different 404 error code that goes into the htaccess file for an https vs. http? Appreciate your feedback on this issue
Technical SEO | | Manifestation0 -
Help creating a 301 redirect in my htaccess file
Hi Guys, I'm trying to build a 301 file with the file requirements: It should be visible only for Google and other Search Engine Agents. It will have a few direct redirects. A few URL must be dynamic redirect. For example each page the starts with olddomain.com/category and is not in the list of of direct redirects should be redirect for newdomain.com/category Here is my start point: #301 Starts here Set the agents RewriteEngine On
Technical SEO | | Felip3
RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
RewriteCond %{HTTP_USER_AGENT} msnbot [OR]
RewriteCond %{HTTP_USER_AGENT} Slurp Make the direct redirect. Redirect 301 /category/sub1 http://www.newdomain.com/category/sub1
Redirect 301 /category/sub2 http://www.newdomain.com/category/sub2 Redirect everything else Redirect 301 /category/* http://www.newdomain.com/category #End of my 301 Will that work how I want? is there anything wrong?0 -
Htaccess redirect with question mark
Hi I have a problem setting up my htaccess for a specific page that has a question mark in the link, and one that has a space in the link and also a question mark. So I would like 2 redirects in my htaccess like that: www.olddomain.com/page.php?page=pagename1 to www.newdomain.com/newpage1.html www.olddomain.com/page.php?page=page name2 to www.newdomain.com/newpage2.html I have tried with something like this but doesn't work: RewriteEngine on RewriteRule ^page.php?page=pagename1 "http://www.newdomain.com/newpage1.html" [R=301,L] RewriteRule ^page.php?page=page name2 "http://www.newdomain.com/newpage2.html" [R=301,L] Could someone tell me what exactly I have to change? Thanks
Technical SEO | | darkanweb0 -
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