Redirecting from _ to - ?
-
hi everyone,
I need your help!
What's the best way to redirect a lot of urls from sign _ to sign - ?
We changed our e-shop CMS and we don't use that _ anymore.
We have more than 100.000 URLs and you can imagine that we don't to do by hand.
Any chance of doing it with .htaccess easily?
Thanks!
-
Yes, you can use the following two rules, in this exact order, in your .htaccess file. I'm assuming you've got mod_rewrite on.
RewriteRule ^([^]*)([^]*.) $1-$2 [N]
RewriteRule ^([^_])([^]*)$ /$1-$2 [L,R=301]The first bracketed group in each rule -- ([^_]*) -- matches every group of characters that isn't an underscore. The first rule rewrites every underscore in the URL to a hyphen, until there's only one underscore left. At this point, control passes to the second rule, which replaces that final underscore with a hyphen, and 301 redirects to that page.
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
-
Index Bloat: Canonicalize, Redirect or Delete URLs?
I was doing some simple on-page recommendations for a client and realized that they have a bit of a website bloat problem. They are an ecommerce shoe store and for one product, there could be 10+ URLs. For example, this is what ONE product looks like: example.com/products/shoename-color1 example.com/products/shoename-color2 example.com/collections/style/products/shoename-color1 example.com/collections/style/products/shoename-color2 example.com/collections/adifferentstyle/products/shoename-color1 example.com/collections/adifferentstyle/products/shoename-color2 example.com/collections/shop-latest-styles/products/shoename-color1 example.com/collections/shop-latest-styles/products/shoename-color2 example.com/collections/all/products/shoename-color1 example.com/collections/all/products/shoename-color2 ...and so on... all for the same shoe. They have about 20-30 shoes altogether, and some come in 4-5 colors. This has caused some major bloat on their site and I assume some confusion for the search engine. That said, I'm trying to figure out what the best way to tackle this is from an SEO perspective. Here's where I've gotten to so far: Is it better to canonicalize all URLs, referencing back to one "main" one, delete all bloat pages re-link everything to the main one(s), or 301 redirect the bloat URLs back to the "main" one(s)? Or is there another option that I haven't considered? Thanks!
Intermediate & Advanced SEO | | AJTSEO0 -
URL Too Long vs. 301 Redirect
We have a small number of content pages where the urls paths were setup before we started looking really hard at SEO. The paths are longer than recommended (but not super crazy IMHO) and some of the pages get a decent amount of traffic. Moz suggests updating the URLs to make them shorter but I wonder if anyone has experience with the tradeoffs here. Is it better to mark those issues to be ignored and just use good URLs going forward or would you suggest updating the URLs to something shorter and implementing a 301 redirect?
Intermediate & Advanced SEO | | russell_ms0 -
301 redirection help needed!
Hi all, So if we used to have a domain (let's say olddomain.com) and we had a new site created at newdomain.com how do we properly setup redirects page to page. Caveat, the urls have changed so for instance the old page oldomain.com/service is now newdomain.com/our-services on the new site. Do we need to have hosting on the old site? Do we need to setup individual 301s for each page corresponding to the new page? Just looking for the easiest way to do this CORRECTLY. Thanks, Ricky
Intermediate & Advanced SEO | | RickyShockley3 -
Redirecting an IP address
Just taken over a new client who recently moved from A.N. other platform to Shopify. I just found reference to their old website IP address and it appears to be not redirecting. Can I simply use something like Traffic Control (Shopify app) to redirect to the new domain?
Intermediate & Advanced SEO | | muzzmoz0 -
303 Redirects Search Engine Friendly?
Do 303 redirects work more like 301s or more like 302s when it comes to passing SEO authority?
Intermediate & Advanced SEO | | MiguelSalcido0 -
301 redirect from one domain to other domain, How To?
Hi, I need to redirect 150 products pages from http://www.filtrationmontreal.com/ to http://www.furnacefilterscanada.com/ How can I do this? Is there a tool or anything I can do to do 301 from one domain to another one? Can I use Google Webmaster Tool? Thank you, BigBlaze
Intermediate & Advanced SEO | | BigBlaze2050 -
Interesting 302 redirect situation - could they be a good idea??
Just started with a new SEO client. The site is built on Sharepoint Server 2007 running Windows Server 2003 R2 on IIS 6.5 (I know, fun times for me). Being a standard crappy Windows setup, URLs and canonicalization is a huge issue: first and foremost, we get a 302 redirect from the root www.example.com to www.example.com/Pages/default.aspx Now standard SEO best practices dictate that we rewrite and redirect these pages so they're clean URLs. However that may or may not be possible in the current environment - so is the next best thing to change those to 301s so at least link authority is passed better between pages? Here's the tricky thing - the 302s seem to be preventing Google from indexing the /Pages/default.aspx part of the URL, but the primary URL is being indexed, with the page content accurately cached, etc. So, www.example.com 302 redirects to www.example.com/Pages/default.aspx but the indexed page in Google is www.example.com www.example.com/sample-page/ 302 redirects www.example.com/sample-page/Pages/default.aspx but the indexed page in Google is www.example.com/sample-page/ I know Matt Cutts has said that in this case Google will most likely index the shorter version of the URL, so I could leave it, but I just want to make sure that link authority is being appropriately consolidated. Perhaps a rel=canonical on each page of the source URL? i.e. the www.example.com/sample-page/ - however is rel=canonical to a 302 really acceptable? Same goes for sitemaps? I know they always say end-state URLs only, but as the source URLs are being indexed, I don't really want Google getting all the /Pages/default.aspx crap. Looking for thoughts/ideas/experiences in similar situations?
Intermediate & Advanced SEO | | OddDog0 -
Are there any negatives to channeling my links through a 301 redirect?
I'm channeling 1000's of links through another url with a 301 redirect. I've thought this through and can't see any downside to doing this, but I want to get your opinion. Can you see any downside to doing this? With regards to passing anchor text, PR, PA, etc? Since this is done with sites all the time when they change urls, I can't see Google being able to penalize me for this....can you? What do you think?
Intermediate & Advanced SEO | | Brian-M0