0

我在 .htaccess 文件中有一行:

RewriteRule ^(.*)$ index.php?page=$1 [NC,L]

和 index.php 中的一行:

$page = $_GET['page']; echo $page;

如果我去http://www.example.com/test-page,它会返回 index.php。

我发现修复它的唯一方法是:

RewriteRule ^(.*)/$ index.php?page=$1 [NC,L]

如果我去http://www.example.com/test-page/它可以工作并输出测试页。

但是,我不希望网页使用http://www.example.com/test-page/,我希望它使用http://www.example.com/test-page

我该如何解决这个问题,最好不要在内部重写中添加将 / 添加到 url 末尾的规则......?

4

1 回答 1

1

尝试

RewriteRule ^(.*)$ /index.php?page=$1 [NC,L]

或尝试这样的事情

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

这会将所有流量重定向到 index.php。您可以使用 eg$_SERVER[REQUEST_URI]来获取您的路径。

于 2012-06-03T21:45:06.643 回答