我只想要:
www.domain.com/index.php?lang=en » www.domain.com/en/
www.domain.com/category.php?lang=en&cat=namecategory » www.domain.com/en/namecategory/
这是我的.htaccess
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.html/$1
RewriteRule /([^/]+)/([^.]+)/$ scale.php?lang=$1&categoria=$2 [L,QSA]
RewriteRule /([^/]+)/$ index.php?lang=$1 [L,QSA]
我对索引页面没有问题,但是对于类别页面,如果我执行print_r($ GET),我有:
Array
(
[lang] => en
[categoria] => namecategory//namecategory
)
所以url重写正常,但后来我有变量问题。 有人可以帮帮我吗?
感谢。
答案 0 :(得分:1)
尝试:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([a-z]{2})/([^.]+)/$ scale.php?lang=$1&categoria=$2 [L,QSA]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([a-z]{2})/$ index.php?lang=$1 [L,QSA]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.html/$ [L]
您需要将条件应用于所有3个规则,因此您需要为每个规则复制3个规则。您还需要在匹配所有规则的规则之前发生语言匹配规则((.*)
)
答案 1 :(得分:0)
您可以使用:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ([^/]+)/([^.]+)/?$ scale.php?lang=$1&categoria=$2 [L,QSA]
RewriteRule ([^/]+)/?$ index.php?lang=$1 [L,QSA]
RewriteRule ^(.*)$ index.html/$1 [L]