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
-
Need advice on redirects
Hi, I have new web addresses for my subpages. None if them have external links. Should I do redirects to the new pages or just leave the old pages in 404 and let google crawl and rank the new page. I am asking because my current pages don’t have a good ranking and I am thinking starting with a clean url is better. Thank you,
Intermediate & Advanced SEO | | seoanalytics1 -
When should you redirect a domain completely?
We moved a website over to a new domain name. We used 301 redirects to redirect all the pages individually (around 150 redirects). So my question is, when should we just kill the old site completely and just redirect (forward/point) the old domain over to the new one?
Intermediate & Advanced SEO | | co.mc0 -
Domain Name Redirect Question
My agency just built a new website for a client who is a franchisee. Â It's not launched yet - it's currently under an IP address. Â I suggested to client that he buy a keyword-rich domain name for it, which he did. Then he found out that the franchisor will not allow it to be his main domain name. They want him to use a domain name with the franchisor name in it. Â But they WILL allow him to put a 301 redirect on that franchisor-approved domain name, and redirect it to his keyword-rich domain name. He is interested in having my agency perform an SEO Campaign for this new website. But would SEO and link marketing work for a website that has a new non-keyword domain name that 301 redirects to a new keyword-rich domain name?
Intermediate & Advanced SEO | | netsites0 -
Redirection question
How would I redirect this URL: http://www.members.mysite.com/ to this URL: http://www.mysite.com/ ? I cant figure it out
Intermediate & Advanced SEO | | JohnPeters0 -
Redirect 301
Hi, I `m redirecting some pages in  htaccess The first 15 pages that i redirected it worked. But the last 3 dont work, and i cant  figure it out why it is not working. Redirect 301 /analyseverktoy/ /webanalyse
Intermediate & Advanced SEO | | SGacic
Redirect 301 /index.php/ledige-stillinger/Â /
Redirect 301 /?page_id=352/ / Anu suggestions?0 -
Can there be to many 301 redirects
Is it possible to have to many 301 redirects. Â I am currently looking at 156 of them. Does this create any quality issues with regard to site performance or any other issues. Thank you for your consideration!
Intermediate & Advanced SEO | | APICDA0 -
Homepage 302 redirect - Which option makes most sense?
Edit: Here's a simplified version of this issue and how I have fixed it thus far. On AmbitionSnowskates.com, there is a video section. There is no content on this page, it 302 redirects to the newest video. If you access ambitionsnowskates.com/video/, you are redirected to ambitionsnowskates.com/video/safari-time/. The original post (OP) was about a site with recurring events. There is a cycle between to which subpage the homepage should redirect. For this reason, I was wondering if I should redirect mysite.com to mysite.com/active-subpage/ or the other way around (and have the content directly on the homepage). I was also wondering how this will affect the result in SERPs. It turns out Google shows the title and description of the destination page, but shows the URL of the original URL (the homepage). Knowing this, I can tailor my meta descriptions to be about both the company and the current event; a mix of the two means I won't have to switch or duplicate meta descriptions between active events. I do appreciate the real solution though: in my opinion there should be unique content on the homepage with according CTA. I'm trying to push this as the best fix, with redirections being an alternative, but albeit more complex, solution. Again sorry for being so unclear. I wish I had had an example from the beginning. 🙂 I'm leaving this opened in case someone wants to chime in. Ben Hey guys, I need a hand on this one 🙂 We have a website with 3 events and we want the homepage to show the upcoming event. Event 1 is in February Event 2 is in April Event 3 is in June These events are recurrent year after year. Currently the homepage shows the content of event 1 at the root level (site.com/) . The other events have a unique URL (site.com/event-2, site.com/event-3). Later in the year, after event 1 is over, we change the homepage content to event 2 and move event 1 to its own URL. In other words... Current structure Today: Event 1: site.com/ Event 2: site.com/event-2 Event 3: site.com/event-3 In March: Event 1: site.com/event-1 Event 2: site.com/ Event 3: site.com/event-3 And so on. I want to make sure each event has its own URL and is properly indexed. Option A I can redirect the homepage to the right event: site.com -> 302 -> site.com/event-1. If that's the way to go, what will be the SEO impact, i.e. what content will show up in SERPs? The destination page's content/meta description and title? Option B What I could also do is keep the current structure (content moved to the root), but redirect temporarily the event's unique URL to the homepage: Today: Event 1: site.com/ Event 1: site.com/event-1 -> 302 -> site.com/ Event 2: site.com/event-2 Event 3: site.com/event-3 In March: Event 1: site.com/event-1 Event 2: site.com/ Event 2: site.com/event-2 -> 302 -> site.com/ Event 3: site.com/event-3 And so on. Again, if that's the way to go, how will this impact SERPs, which title and description will I see for the homepage and individual events? If you have other options, I'm all ears! Thanks a lot! (I mean it) -Ben
Intermediate & Advanced SEO | | BenoitQuimper0 -
Regarding 301 Redirect!
Hello, I heard that 301 redirect can be good for newly registered domain names can i buy a old domain name and put 301 redirect on it to my newly registered niche market domain name. Shall i buy only 1 domain name and put 301 redirect to my newly registered domain names or i can do this for more than 1 old domains i purchased?
Intermediate & Advanced SEO | | anand20100