.htaccess redirect folder to a url

后端 未结 4 1112
小鲜肉
小鲜肉 2020-12-14 00:55

I\'m trying to redirect a folder and all its sub files to a URL with a .htaccess file.

But

Redirect 301 /abc/cba/ http://www.aaa.com/
相关标签:
4条回答
  • 2020-12-14 01:12

    By default, Redirect sort of maps the path node to a new path node, so anything after the first path gets appended to the target URL.

    Try:

    RedirectMatch 301 ^/abc/cba/ http://www.aaa.com/?
    

    Or if you'd rather use mod_rewrite instead of mod_alias:

    RewriteEngine On
    RewriteRule ^/?abc/cba/ http://www.aaa.com/? [R=301,L]
    
    0 讨论(0)
  • 2020-12-14 01:23

    here's another example of a mod_rewrite rule that worked for me

    I wanted to redirect a sub directory to the root of the same domain.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^sub_directory/(.*)$ /$1 [R=301,NC,L]
    </IfModule>
    

    more examples can be found here:http://coolestguidesontheplanet.com/redirecting-a-web-folder-directory-to-another-in-htaccess/

    0 讨论(0)
  • 2020-12-14 01:24

    I perfer the following method:

     RewriteEngine on
     RewriteCond %{REQUEST_URI}  ^/somedir           [NC]
     RewriteRule /(.*) http://somesite.com/lost/$1 [R=301,L]
    
    0 讨论(0)
  • 2020-12-14 01:30

    I had to reroute urls from old site version to new version, so here is what I did to reroute any links from about-us/* to about-us.html

    RewriteEngine on
    RewriteRule ^about-us/(.*)$ about-us.html [R=301,L]
    

    What it doesn't do is rewrite something like domain.com/about-us/thing.html => domain.com/about-us.html .

    It does work for things without extensions domain.com/about-us/something-in-url => domain.com/about-us.html

    I added the lines below to redirect .jpg and .png, but it didn't work for .html, I can't find out why.

    RewriteRule ^about-us/(.*).jpg about-us.html [R=301,L]
    RewriteRule ^about-us/(.*).png about-us.html [R=301,L]
    
    0 讨论(0)
提交回复
热议问题