添加一个斜杠mod_rewrite

只是想知道如何在我的URL的末尾使用Mod_Rewrite添加尾部的斜线?

这是我的.htaccess文件目前:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]*)$ index.php?pageName=$1 

我的url显示如下:

WWWW。****。com /网页

我希望它显示如下:

WWWW。****。com /网页/

该URL在内部持有GET请求,但我希望它看起来像一个真正的目录。

首先,我们需要启用“ mod_rewrite ”模块。

 # a2enmod rewrite 

然后确保你的configuration文件有

RewriteEngine on

在遵循以下规则之前。

这是规则,将检查是否请求

  • 文件不存在
  • 请求不是为index.php
  • REQUESTED_URI不以/

然后

使外部redirect(301)到您的domain.tld /任何被请求和/追加。 做出给定集合的最后一条规则。

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !index.php RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://domain.tld/$1/ [L,R=301] 

下一个规则

  • 如果新请求,文件不存在
  • 如果目录不存在
  • 如果请求不是针对index.php

然后通过所有请求作为' pageName '参数index.php /使这个最后的规则,并做查询string追加。

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !index.php RewriteRule ^(.*)$ index.php?pageName=$1 [L,QSA]