2014-04-07 35 views
-1

目前我工作在我的网站转移到搜索引擎友好的URL(在本地主机)友好,PHP 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: 我的页面没有加载的引用文件,所有*.css*.js等被忽略?

+0

你的重写基地定义在哪里?我相信你错过了正确的位置。 –

回答

0

问题2 - 问题出现了,因为您没有提到基本路径。

您需要指定加载css和其他引用的基本路径。

尝试<head>标签<base href="http://www.MYSITE.com/" />

这将加载你的CSS/JS用这个。

+0

我使用@Neeraj Kumar脚本并添加了'',现在页面运行良好。谢谢!! – conmen

0

问题1:这里没有发生重写 - (你只认为它有,因为你的脚本item.php被调用了,因为你在URL中有item,MultiViews已经完成了它的工作) - RewriteRules匹配的路径。 htaccess 从来没有/开头,所以删除它。

问题2:之前已经讨论过很多次(对于知道相对URL完成的基本知识的人也应该明白) - 参见f.e. .htaccess URL Rewrite Problem (Scripts don't load)

1

在.htaccess文件试试这个:

Options +FollowSymLinks 
RewriteEngine on 
RewriteRule item/category/(.*) item.php?category=$1 
0

RewriteEngine叙述在
RewriteBase /站点名称
重写规则^项/([0-9] +)/ $ item.php类别? = $ 1 [L,NC]