【发布时间】:2015-11-29 10:01:14
【问题描述】:
我有一个博客,其中有一个categories.php 页面中的类别编号。原始 URL 如下所示:
http://myname.com/articles.php?category=music
我已经简化为:
http://myname.com/articles/music
使用:
RewriteRule ^articles/([\w-]+)/?$ articles.php?cat=$1 [NC,L,QSA]
但是有没有办法将其进一步简化为:
http://myname.com/music
--
更新:
我已经解决了最初的问题,但现在我遇到了另一个问题。我的 .htaccess 是:
Options -MultiViews
DirectoryIndex articles.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ articles.php?cat=$1 [NC,L,QSA]
RewriteRule ^([\w-]+)/([0-9]+)/?$ articles.php?cat=$1¤tpage=$2 [NC,L,QSA]
RewriteRule ^([0-9]+)/([\w-]+)/?$ article.php?id=$1&title=$2 [NC,L,QSA]
RewriteRule ^articles articles.php
RewriteRule ^categories categories.php
RewriteRule ^about about.php
RewriteRule ^feed feed.php
RewriteRule ^privacy privacy.php
当我访问http://myname.com/articles 和http://myname.com/article... 时一切正常,但是当我访问http://myname.com/categories、http://myname.com/feed 等时,我被重定向回主页。任何想法为什么会这样?
【问题讨论】:
标签: regex .htaccess url mod-rewrite rewrite