0

我正在尝试为我的网站进行 SEO 排序,但我似乎无法弄清楚这种情况。

我想要 4 个查询参数,, $cat, $subcat,$page$othervars

但我需要一个 htaccess 规则来允许这些值:

  1. domain.com/cat/page
  2. domain.com/cat/subcat/page
  3. domain.com/cat
  4. domain.com/cat/subcat/page/其他

我怎样才能做到这一点,到目前为止我所拥有的是:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /beta/index.php?cat=$1&cat2=$2&page=$3&var=$4 [L]
4

3 回答 3

1

改为在 PHP 中进行解析!

.htaccess:

RewriteEngine On
RewriteRule ^(.*)$ /beta/index.php?var=$1 [L]

...在 index.php 中

$vars = explode("/",$_GET['var']);
$cat = isset($vars[0]) ? $vars[0] : false;
$subcat = isset($vars[1]) ? $vars[1] : false;
$page = isset($vars[2]) ? $vars[2] : false;
$othervars = isset($vars[3]) ? $vars[3] : false;
于 2012-05-27T20:04:49.107 回答
1
RewriteEngine On
RewriteRule ^([^/]+)/?$ /beta/index.php?cat=$1 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ /beta/index.php?cat=$1&page=$2 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /beta/index.php?cat=$1&cat2=$2&page=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /beta/index.php?cat=$1&cat2=$2&page=$3&var=$4 [L]
于 2012-05-27T20:50:31.110 回答
0

我认为这些使用 4 RewriteRules 会更好:

RewriteEngine On
RewriteRule ^([^/]+)/?$ /beta/index.php?cat=$1 [L,R=301]
RewriteRule ^([^/]+)/([^/]+)/?$ /beta/index.php?cat=$1&page=$2 [L,R=301]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /beta/index.php?cat=$1&cat2=$2&page=$3 [L,R=301]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /beta/index.php?cat=$1&cat2=$2&page=$3&var=$4 [L,R=301]
于 2012-05-27T20:08:20.767 回答