简体   繁体   中英

htaccess rewrite add trailing slash

I have following url :

http://localhost/PROJECTNAME?gallery_detail.php?id=1

Which i am rewriting to this : http://localhost/PROJECTNAME/username/id

I have used following code for that:

RewriteRule /(\w+)$ gallery_detail.php?id=$1 [L]
RewriteRule /$ gallery_detail.php?id=$1 [L]

And it's working fine but when i am removing the id and slash it redirects me to the 404 page. how can i forcefully add trail slash at the end of the url or is there any other way to do that.

Please help!!!

It's because you are using a leading slash in RewriteRule's pattern (See your first rule) . htaccess doesnot accept leading slash in its pattern,you need to remove this. You can use the following rule with an optional trailing slash :

RewriteRule ^(\w+)/?$ /gallery_detail.php?id=$1 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM