简体   繁体   English

htaccess重写添加结尾斜杠

[英]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 我正在对此重写: 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. 而且工作正常,但是当我删除I​​D并使用斜杠时,它将我重定向到404页面。 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) . 这是因为您在RewriteRule的模式中使用了斜杠(请参阅第一个规则)。 htaccess doesnot accept leading slash in its pattern,you need to remove this. htaccess的模式不接受斜杠,您需要删除它。 You can use the following rule with an optional trailing slash : 您可以将以下规则与可选的斜杠一起使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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