list of redirects not working

时间:2015-07-31 20:22:01

标签: regex apache .htaccess mod-rewrite redirect

I've got a list of redirects that isn't working. I'm redirecting 1 domain to another. There are about 10 pages that I have want redirected to unique pages. The rest I want redirected to the home page.

Currently, it redirects everything to the home page including these location pages.

Thoughts?

Options +FollowSymLinks
RewriteEngine on
# Redirect individual store pages to NewSoundHearing.com
RewriteRule ^/about-us/eugene-or$  http://www.newsoundhearing.com/locations/eugene/ [L,R=301,NC]
RewriteRule ^/about-us/gearhart-or$  http://www.newsoundhearing.com/locations/gearhart/ [L,R=301,NC]
RewriteRule ^/about-us/gresham-or$  http://www.newsoundhearing.com/locations/gresham/ [L,R=301,NC]
RewriteRule ^/about-us/king-city-or$  http://www.newsoundhearing.com/locations/king-city/ [L,R=301,NC]
RewriteRule ^/about-us/mcminnville%20-%20or$  http://www.newsoundhearing.com/locations/mcminnville/ [L,R=301,NC]
RewriteRule ^/about-us/north-bend-or$  http://www.newsoundhearing.com/locations/north-bend/ [L,R=301,NC]
RewriteRule ^/about-us/north-plains-or$  http://www.newsoundhearing.com/locations/north-plains/ [L,R=301,NC]
RewriteRule ^/about-us/oregon-city-or$  http://www.newsoundhearing.com/locations/oregon-city/ [L,R=301,NC]
RewriteRule ^/about-us/portland-or$ http://www.newsoundhearing.com/locations/portland/ [L,R=301,NC]
RewriteRule ^/about-us/west-portland-or$ http://www.newsoundhearing.com/locations/portland-west/ [L,R=301,NC]
RewriteRule ^/about-us/salem-or$ http://www.newsoundhearing.com/locations/salem/ [L,R=301,NC]
RewriteRule ^/about-us/vancouver-wa$ http://www.newsoundhearing.com/locations/vancouver/ [L,R=301,NC]
# Redirect everything else to NewSoundHearing.com
RewriteRule ^(.+)$ http://www.newsoundhearing.com/ [R=301,NC]

1 个答案:

答案 0 :(得分:0)

  1. 从规则模式中删除前导斜杠
  2. 在最后一条规则中重定向除/locations以外的所有内容,以避免再次重定向顶部网址。
  3. 你的规则如下:

    Options +FollowSymLinks
    RewriteEngine on
    
    # Redirect individual store pages to NewSoundHearing.com
    RewriteRule ^about-us/eugene-or$ /locations/eugene/ [L,R=301,NC]
    RewriteRule ^about-us/gearhart-or$ /locations/gearhart/ [L,R=301,NC]
    RewriteRule ^about-us/gresham-or$ /locations/gresham/ [L,R=301,NC]
    RewriteRule ^about-us/king-city-or$ /locations/king-city/ [L,R=301,NC]
    RewriteRule ^about-us/mcminnville%20-%20or$ /locations/mcminnville/ [L,R=301,NC]
    RewriteRule ^about-us/north-bend-or$ /locations/north-bend/ [L,R=301,NC]
    RewriteRule ^about-us/north-plains-or$ /locations/north-plains/ [L,R=301,NC]
    RewriteRule ^about-us/oregon-city-or$ /locations/oregon-city/ [L,R=301,NC]
    RewriteRule ^about-us/portland-or$ /locations/portland/ [L,R=301,NC]
    RewriteRule ^about-us/west-portland-or$ /locations/portland-west/ [L,R=301,NC]
    RewriteRule ^about-us/salem-or$ /locations/salem/ [L,R=301,NC]
    RewriteRule ^about-us/vancouver-wa$ /locations/vancouver/ [L,R=301,NC]
    
    # Redirect everything else to NewSoundHearing.com
    RewriteRule !^locations/ http://www.newsoundhearing.com/ [R=301,L,NC]