2012-01-09 58 views
1

我想安装一个网站,我创建永久链接就像wordpress,但具体到该网站。所以,当用户点击文章应该想.htaccess中的多个重写规则重定向在所需的页面

http://www.sitename.com/url-slug 

此外,当用户点击目录应该重定向像这样

http://www.sitename.com/category/category-slug 

同样,在台,用户,页面点击时,它应该分别重定向像

http://www.sitename.com/sets/set-slug 

http://www.sitename.com/user/user-full-name 
http://www.sitename.com/page/page-slug 

以下是我使用.htaccess中的代码,我敢肯定是不正确

Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule (.*)$ ./single.php?id=$1 
RewriteRule ^category/(.*)/ category.php?id=$1 [L] 


Options +FollowSymLinks 
RewriteCond %{THE_REQUEST} ^.*/index.php 
RewriteRule ^(.*)index.php$ http://www.sitename.com/$1 [R=301,L] 

有人可以指导我在哪里出错,我需要这些网页来调用其各自的页面,即single.php,category.php,sets.php,users.php和page.php分别获取并显示数据。我是.htaccess的新手,所以,任何帮助表示赞赏。

回答

9

我假设你已经在你的.htaccess没有其他规则位于诠释你的网站根目录

RewriteEngine on 
RewriteBase/

#if for an existing directory or file 
RewriteCond %{SCRIPT_FILENAME} -d 
RewriteCond %{SCRIPT_FILENAME} -f 
#then do nothing 
RewriteRule . - [L] 

#otherwise 
#if it is for a slug (assuming alphanumeric and dashes), send to single 
RewriteRule ^([-a-zA-Z0-9]+)/?$ single.php?id=$1 [L] 

#if a category 
RewriteRule ^category/([-a-zA-Z0-9]+)/?$ category.php?id=$1 [L,NC] 

#if a sets 
RewriteRule ^sets/([-a-zA-Z0-9]+)/?$ sets.php?id=$1 [L,NC] 

#if a sets 
RewriteRule ^user/([-a-zA-Z0-9]+)/?$ users.php?id=$1 [L,NC] 

#if a page 
RewriteRule ^page/([-a-zA-Z0-9]+)/?$ page.php?id=$1 [L,NC] 
+0

感谢的人!这是我喜欢关于Stackoverflow的。你直接和准确地得到答案。太感谢了。 – user4203 2012-01-10 14:27:33