无法将路径信息移动到 htaccess 中的查询字符串
Trouble moving path information to a query string in htaccess
我想将 www.mysite.com/a/b/slug
重写为 www.mysite.com/a/b/index.php?id=slug
。
我正在尝试捕获路径的最后一段,即 slug
并在查询字符串中使用它——类似于此 example.
所以我的 .htaccess
中有以下几行,位于我的 public_html
文件夹中:
RewriteEngine on
RewriteRule ^a/b/([^/]+) a/b/index.php?id= [L]
在我的a/b/index.php
,当我去www.site.com/a/b/slug
,$_GET['id']
returns index.php
反对slug
。我不知道为什么。
如何捕获最后一段并将其用于查询字符串?
您需要在 .htaccess 中添加重写条件 - 目前,它也在尝试重写 /a/b/index.php
!
尝试添加 RewriteCond %{REQUEST_FILENAME} !-f
和 RewriteCond %{REQUEST_FILENAME} !-d
我想将 www.mysite.com/a/b/slug
重写为 www.mysite.com/a/b/index.php?id=slug
。
我正在尝试捕获路径的最后一段,即 slug
并在查询字符串中使用它——类似于此 example.
所以我的 .htaccess
中有以下几行,位于我的 public_html
文件夹中:
RewriteEngine on
RewriteRule ^a/b/([^/]+) a/b/index.php?id= [L]
在我的a/b/index.php
,当我去www.site.com/a/b/slug
,$_GET['id']
returns index.php
反对slug
。我不知道为什么。
如何捕获最后一段并将其用于查询字符串?
您需要在 .htaccess 中添加重写条件 - 目前,它也在尝试重写 /a/b/index.php
!
尝试添加 RewriteCond %{REQUEST_FILENAME} !-f
和 RewriteCond %{REQUEST_FILENAME} !-d