如何使用模组重写重定向 URL


How to use mod rewrite to redirect URL?

我想将不以 slash 结尾的 URL 重定向到以 slash 结尾。

注意:.htaccess 位于mysite目录中

.htaccess

<need help here>

不想要网址

http://localhost/mysite/index.php
http://localhost/mysite/blog
http://localhost/mysite/blog/110084

所需的网址

http://localhost/mysite/
http://localhost/mysite/blog/
http://localhost/mysite/blog/110084/

非常感谢。

RewriteEngine on
RewriteBase /Application
RewriteCond $1 !^(index'.php|images|table-images|robots'.txt|styles|js|uploads)
RewriteRule ^(.*)$ index.php/$1 [L]

您可以将此规则用作RewriteEngine On行下方的第一条规则,为非文件添加尾部斜杠:

# add a trailing slash to directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302]