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
-
301 redirect with DNS?
Quick question. Is it possible to 301 redirect a non-www to www. (properly in terms of SEO) with DNS (C Name, A name, or other) ..have searched around and found conflicting information. Would like to know a definite answer. I usually implement all 301 redirects with htaccess. However have a client situation where we only have access to the CMS, but which does have DNS settings. thanks in advance, Greg
Intermediate & Advanced SEO | | GregDixson0 -
A 302 Redirect Question | Events Page Updates
Hello Moz World, I have a client that has a TON, like close to a thousand pages that have a 302 redirect set up. After further investigation, I found that every month they update their events page & Demo Request page, and the old events pages still exist but, get a 302 redirect to the updated page. From what I gather, this is a default mechanism set up by the hosting provider. My questions; is this an example of when to use a Rel=canonical? Also, is there a method for integrating this without having to go into every page and integrate the code snippet? And Lastly, How should I go about ensuring this doesn't happen in the future? Thanks ahead of time, you guys rock! B/R Will H.
Intermediate & Advanced SEO | | MarketingChimp100 -
What happens to 301 redirect if the site taken down?
I understand 301 redirect carries over the page value to the page its being redirected to. However what happens if for example, I do a 301 redirect from example.com to example.co.uk, 2 months later I take down hosting and cancel domain for example.com, would I lose the page value that was being carried over to example.co.uk? Do I need to keep both domains active?
Intermediate & Advanced SEO | | Marvellous0 -
Fetch as Google - Redirected
Hi I have swaped from HTTP to HTTPS and put a redirect on for HTTP to redirect to HTTPS. Â I also put www.xyz.co.uk/index.html to redirect to www.xyz.co.uk When I fetch as Google it shows up redirect! Does this mean that I have too many 301 looping? Do I need the redirect on index.html to root domain if I have a rel conanical in place for index.html htaccess (Linix) - RewriteCond %{HTTP_HOST} ^xyz.co.uk
Intermediate & Advanced SEO | | Cocoonfxmedia
RewriteRule (.*) https://www.xyz.co.uk/$1 [R=301,L] RewriteRule ^$ index.html [R=301,L]0 -
Redirecting non-www pages to www ones
Hello:
Intermediate & Advanced SEO | | romanbond
I'm trying to consolidate all the link juice and see that some of my pages are linked to by using both www.mysite.com/whatever.html and mysite.com/whatever.html.
Is there a safe re-write rule that not just redirects non-www(s) to www(s), but designates the redirect as 301, so link juice will be transfered as well. If not RewriteRule, are there any other ways to accoplishe this? And the last question: can this be solved by simply setting Preffered domain in google webmaster tools to display www URL? Any help will be appreciated.0 -
301 redirect with /? in URL
For a Wordpress site that has the ending / in the URL with a ? after it... how can you do a 301 redirect to strip off anything after the / For example how to take this URL domain.com/article-name/?utm_source=feedburner and 301 to this URL domain.com/article-name/ Thank you for the help
Intermediate & Advanced SEO | | COEDMediaGroup0 -
Sites with dynamic content - GWT redirects and deletions
We have a site that has extremely dynamic content. Every day they publish around 15 news flashes, each of which is setup as a distinct page with around 500 words.   File structure is  bluewidget.com/news/long-news-article-name.  No timestamp in URL. After a year, that's a lot of news flashes. The database was getting inefficient (it's managed by a ColdFusion CMS) so we started automatically physically deleting news flashes from the database, which sped things up. The problem is that Google Webmaster Tools is detecting the freshly deleted pages and reporting large numbers of 404 pages.  There are so many 404s that it's hard to see the non-news 404s, and I understand it would be a negative quality indicator to Google having that many missing pages. We were toying with setting up redirects, but the volume of redirects would be so large that it would slow the site down again to load a large htaccess file for each page. Because there isn't a datestamp in the URL we couldn't create a mask in the htaccess file automatically redirecting all bluewidget.com/news/yymm* to bluewidget.com/news These long tail pages do send traffic, but for speed we only want to keep the last month of news flashes at the most. What would you do to avoid Google thinking its a poorly maintained site?
Intermediate & Advanced SEO | | ozgeekmum0 -
Question about 301 redirect for trailing / ?
I am cleaning up a fairly large site. Some pages have a trailing slash on the end some don't. Some of the existing backlinks built used a trailing slash in the url and some didn't. We aren't concerned with picking a particular one but just want to get one set and stick to it from now on. I am wondering, would I clean this up within the same redirect in the htaccess file that takes care of the www and non www? example RewriteEngine On
Intermediate & Advanced SEO | | PEnterprises
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.com/ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [L,R=301] I currently use that to redirect the www. to the non www as you can see. However here is what I was confused about. Would this code be enough to redirect ALL pages with a / to the ones without? or would I also need to add another code (so there is 2) to my htaccess like below? RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com/ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [L,R=301] RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.com/ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [L,R=301] That way, now, even the non www pages with a trailing slash will redirect to the non www without the trailing slash. Hopefully you understand what I am getting at. I just want to redirect EVERYTHING to the non www WITHOUT a / Thank you Jake0