How can I use an .htaccess redirect for a partial path?

前端 未结 1 1078
误落风尘
误落风尘 2021-01-03 00:45

I had to adjust some paths on my site and I need to use .htaccess to redirect the items on the chance a user accesses the old url.

For example my old urls (relative)

相关标签:
1条回答
  • 2021-01-03 01:17

    You can use either mod+alias:

    Redirect 301 /old-path /new-path
    

    or using mod_rewrite:

    RewriteEngine On
    RewriteRule ^/?old-path/(.*)$ /new-path/$1 [L,R=301]
    

    These could be in the htaccess file in your document root or in the server/vhost config. If you already have rewrite rules somewhere, you may just want to stick with mod_rewrite because redirecting with mod_alias while using mod_rewrite can sometimes give conflicting results.

    0 讨论(0)
提交回复
热议问题