[英]htaccess rewrite remove trailing slash
I have the following rewrite rules which work perfectly 我有以下重写规则,可以很好地工作
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\/$ /social/single_post.php?name=$1&t=$2&id=$3 [L]
RewriteRule ^([^/]*)\/$ /social/user.php?user=$1 [L]
Example: http://myurl.com/username/ points to http://myurl.com/social/user.php?user=username 示例: http : //myurl.com/username/指向http://myurl.com/social/user.php?user=username
I want to remove the trailing slash from the second rewrite rule so it will return as follows: 我想从第二个重写规则中删除尾部斜杠,因此它将返回如下:
Example: http://myurl.com/username points to http://myurl.com/social/user.php?user=username 示例: http : //myurl.com/username指向http://myurl.com/social/user.php?user=username
RewriteRule ^([^/]*)$ /social/user.php?user=$1 [L]
The problem is when I do this, the entire domain is redirecting 问题是当我这样做时,整个域都在重定向
so: http://myurl.com/ points to http://myurl.com/social/user.php?user= 因此: http : //myurl.com/指向http://myurl.com/social/user.php?user=
and http://myurl.com points to http://myurl.com/social/user.php?user= 而http://myurl.com指向http://myurl.com/social/user.php?user=
Obviously I don't want those last two things happening. 显然,我不希望最后两件事发生。 How can I modify my htaccess to achieve the desired outcome?
如何修改htaccess以获得所需的结果?
Try this, 尝试这个,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\/$ /social/single_post.php?name=$1&t=$2&id=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\/$ /social/user.php?user=$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.