简体   繁体   中英

.htaccess Rewrite with multiple rules

I need to update my .htaccess to handle rewrite of URL in following format.

rewriting this url: /score.php?state=FL&name=somename&id=123 to /FL/somename-event/123-event

and also this rewrite rule: /state.php?state=FL to /FL

I have the following but it generates a 500 error:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)-event$ /score.php?state=$1&name=$2&id=$3 [L]
RewriteRule ^([^/]*)$ /state.php?state=$1 [L]

Use + instead of * to match 1+ characters in your regex and ignore all files and directories from your rewrite rules:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM