【发布时间】:2016-08-08 21:04:08
【问题描述】:
我想使用 RewriteRule,但似乎无法掌握它。
这些是网站的层次:
http://domain.com/artists/artist-name/1/2/3/
http://domain.com/fairytales/fairy-tale-one/1/2/3/
http://domain.com/horrorstories/horror-story-six/1/2/3/
基本上,在 url 中的 '/1/' 之前的目录应该是很酷的 SEO url 名称。
到目前为止我都明白了,正确地重写应该是这样的。
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/artists/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?artist_id=$1&cat_id=$2&style_id=$3
RewriteRule ^/fairytales/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?story_id=$1&cat_id=$2&style_id=$3
RewriteRule ^/horrorstories/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?story_id=$1&cat_id=$2&style_id=$3
.htaccess 在我正在使用的 CentOS 服务器上与 Apache 2.4.23 配合使用。
在经历了许多 500 错误和现在太多的 404 错误之后,我终于要问了。
【问题讨论】:
-
只用一个路由库,有很多选择,而且都比你自己的diy版本更丰富、更健壮:google.co.uk/…
-
我知道!问题是我无法让它工作。
标签: php regex .htaccess mod-rewrite