【发布时间】:2018-08-30 19:27:49
【问题描述】:
我的网站上有许多带有查询字符串的 PHP 页面。我正在尝试更改 SEO 的 URL,为此我正在使用 .htaccess 文件。
我是 .htaccess 的新手,所以这是相当基本的,我不确定我这样做是否正确,或者是否有更好的方法。
我的 .htaccess 文件:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !/.css$
RewriteCond %{REQUEST_URI} !/.js$
RewriteCond %{REQUEST_URI} !/.png$
RewriteCond %{REQUEST_URI} !/.jpg$
RewriteRule ^category/([0-9a-zA-Z]+) category.php?id=$1
RewriteRule ^product/([0-9a-zA-Z]+) product.php?id=$1
RewriteRule ^page/([0-9a-zA-Z]+) page.php?page_id=$1
这使我可以在category/1 访问页面category.php?id=1,对于我有重写规则的其他页面也是如此。但是我的 php 脚本无法再从 URL 访问 $_GET 变量,因此它可以正确重写但现在无法显示任何内容?
【问题讨论】:
-
您是否已经调试过 $_GET (var_dump)?
-
试试
RewriteRule ^(category|product|page)/([0-9a-zA-Z]+) $1.php?id=$2 [PT] -
清除浏览器缓存然后再次测试