htaccess add .html extension for urls with or without trailing slash

前端 未结 2 823
长情又很酷
长情又很酷 2021-01-15 09:10

So to begin with I have a custom url rewrite that sends a request variable to a php script

Rewrite rule is below:

RewriteRule ^([\\w\\/-]+)(\\?.*)?$          


        
2条回答
  •  我在风中等你
    2021-01-15 09:59

    This is supposed to redirect /slug-text to /slug-text.html

    RedirectMatch ^/([\w-]+)/?$ http://domein.com/$1.html 
    

    This is in the case when slug-text is only letters, digits, – and _. Rewrite slug-text.html to a php file and pass the slug as a param:

    RewriteRule ^([\w-]+)\.html$ test/index.php?slug=$1 [R,L] 
    

    If you have both line in your .htaccess the first one will do the redirects from the legacy URLs to the new ones and the second one will process the request.

提交回复
热议问题