我需要更新.htaccess来处理以下格式的URL重写。
重写此网址:
/score.php?state=FL&name=somename&id=123
至
/FL/somename-event/123-event
以及以下重写规则:
/state.php?state=FL
至
/FL
我有以下内容,但它会产生500错误:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)-event$ /score.php?state=$1&name=$2&id=$3 [L]
RewriteRule ^([^/]*)$ /state.php?state=$1 [L]
答案 0 :(得分:0)
使用+
代替*
来匹配正则表达式中的1个以上字符,并忽略重写规则中的所有文件和目录:
RewriteEngine On
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ state.php?state=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/(\d+)-event$ score.php?state=$1&name=$2&id=$3 [L,QSA,NC]