htaccess mod rewrite with optional slash

前端 未结 1 1130
我在风中等你
我在风中等你 2021-01-28 11:57

We\'re switching from an old site to a new site with better URLs for SEO. I\'m trying to do this:

RewriteRule ^products/boots/materialid/(.*)/colour/(.*)$ http:/         


        
相关标签:
1条回答
  • 2021-01-28 12:30

    Try this:

    RewriteRule ^products/boots/materialid/([^/]*)/colour/([^/]*)/?$ http://www.mydomain.com/boots/$2/$1 [R=301,L]
    

    [^/] matches any character that is NOT a slash. /? means an optional trailing slash (note that it is outside of the capturing parentheses, so that it will not be included in the rewritten URL).

    EDIT

    As per your comment, to add an optional /index.php:

    RewriteRule ^products/boots/materialid/([^/]*)/colour/([^/]*)(/|/index\.php)?$ http://www.mydomain.com/boots/$2/$1 [R=301,L]
    
    0 讨论(0)
提交回复
热议问题