【发布时间】:2014-05-19 09:21:31
【问题描述】:
目前我正在努力将我的网站转换为 SEO 友好的 URL(在本地主机中),
这是带有查询字符串的原始 URL:
http://{ip}/sitename/item.php?category=44
我想转换为:
http://{ip}/sitename/item/category/44
.htaccess 文件(与 item.php 相同的目录):
DirectoryIndex index.php
Options -Indexes
<files page>
ForceType application/x-httpd-php
</files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ item.php%{REQUEST_URI} [L]
RewriteRule ^/item/([0-9]+) /item.php?category=$1
</IfModule>
<Files *htaccess>
Deny from all
</Files>
在item.php,我使用$_GET['category']
$category = preg_replace('/[^0-9]/', '', $mysqli->real_escape_string($_GET['category']));
$list = $listing->get_items($category, $mysqli);
if($list == 0){
echo '<p><h2>Page not found</h2></p>';
die();
}
问题 1:
当我加载http://{ip}/sitename/item/category/44时,页面无法获取变量传递给get_item(),页面显示Page not found? 44 是假设返回一个值。
问题 2:
我的页面没有加载referrer文件,所有*.css*.js等都被忽略了?
【问题讨论】:
-
你的重写基定义在哪里?我确定您错过了正确的位置。
标签: php .htaccess friendly-url