So I have the following Rewrite Rules:
RewriteRule ^([a-z0-9_\-]+)(\.php)?$ index.php?page=$1 [NC,L,QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?shop=$1&page=index [NC,L,QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z_-]+).php$ index.php?shop=$1&page=$2 [NC,L,QSA]
Everything seems to work great, if I go to domain.com/shop/ then it works fine and shows the index. If I go to domain.com/shop/about.php then it works perfect.
The only thing that does not work is when I go to domain.com/shop without a trailing slash, it does not display anything I get a bunch of errors.
Does anyone know how to fix this? It's probably something super simple to add to my code but I can't seem to figure it out.
Thanks!
In your second rule, add ?
after trailing slash:
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?shop=$1&page=index [NC,L,QSA]
That will make trailing /
optional
I usually end my rules with /?$
meaning string ending with one slash or no shash.
来源:https://stackoverflow.com/questions/7148454/htacess-rewrite-rule-doesnt-work-without-trailing-slash