Mode Rewrite; with/without trailing slash on end of url?

后端 未结 3 2045
天命终不由人
天命终不由人 2020-12-08 23:52

I basically tried this mode_rewrite rule below. It works with a slash on the end but I want it to work whether it has a trailing slash on the end or not. Basically I want it

相关标签:
3条回答
  • 2020-12-09 00:02
    ...    
    RewriteRule ^(url-rewrite)/?$ page.php [NC]
    ...
    

    The ? after / specifies that there can be none or one / after your url-rewrite, as such it would accept it with or without the trailing /

    0 讨论(0)
  • 2020-12-09 00:19

    The subpattern .[^/]* requires at least one arbitrary character. In your case it’s probably that trailing slash.

    You should better stick to one writing (either with or without trailing slash) and redirect th wrong writing to the proper, like:

    # remove trailing slash
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    
    # add trailing slash
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^.*[^/]$ /$0/ [L,R=301]
    
    0 讨论(0)
  • 2020-12-09 00:24

    plain old regexes:

    RewriteRule ^signup/register/?$ /signup/register.php [NC]
    
    0 讨论(0)
提交回复
热议问题