繁体   English   中英

.htaccess中的多个重写规则以重定向到所需的页面

[英]Multiple Rewrite Rules in .htaccess To Redirect at desired pages

我正在尝试建立一个网站,我在其中创建永久链接,就像wordpress一样,但特定于该网站。 因此,当用户点击文章时,

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的新手,因此,感谢您的帮助。

我假设.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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM