.htaccess重写规则帮助
我已成功设置了一个URL系统,可重定向如下快捷方式:.htaccess重写规则帮助,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我已成功设置了一个URL系统,可重定向如下快捷方式: # http://www.site.com/102/ -> http://www.site.com/102-some-keywords.html RewriteRule ^([0-9]{3})/?$ includes/redirect.php?ref=$1 [L] # http://www.site.com/102-some-keywords.html -> http://www.site.com/templates/defaul
# http://www.site.com/102/ -> http://www.site.com/102-some-keywords.html
RewriteRule ^([0-9]{3})/?$ includes/redirect.php?ref=$1 [L]
# http://www.site.com/102-some-keywords.html -> http://www.site.com/templates/default/index.php?ref=102
RewriteRule ^([0-9]{3})-.*?\.html$ templates/default/index.php?ref=$1 [L]
现在我正在升级到一个多语言系统,并希望在域之后获得语言代码:
# http://www.site.com/fr/102/ -> http://www.site.com/fr/102-some-keywords.html
# http://www.site.com/fr/102-some-keywords.html -> http://www.site.com/templates/default/index.php?loc=fr&ref=102
有些语言是fr,it,es,ru,。。。
我想我需要多个变量$1,$2,但我被这部分卡住了
这里是一个尝试(工作不正常)
您的新代码基本上是正确的,只是您忘记了在
[0-9]
之前的^
(匹配表达式的开头)。仅仅删除这些代码就可以让代码正常工作,但我个人会为国家代码添加更严格的匹配:[a-z]{2}
RewriteRule ^([a-z]{2})/([0-9]{3})/?$ includes/redirect.php?loc=$1&ref=$2 [L]
RewriteRule ^([a-z]{2})/([0-9]{3})-.*?\.html$ templates/default/index.php?loc=$1&ref=$2 [L]
RewriteRule ^([a-z]{2})/([0-9]{3})/?$ includes/redirect.php?loc=$1&ref=$2 [L]
RewriteRule ^([a-z]{2})/([0-9]{3})-.*?\.html$ templates/default/index.php?loc=$1&ref=$2 [L]