简体   繁体   中英

htaccess 500 error when rewriting

My htaccess currently looks like this:

RewriteEngine On
RewriteRule ^Lesson/Add/?([^/]*)/?([^/]*)/?$ ./AddLesson.php?type=$1&data=$2 [NC,L]
RewriteRule ^Lesson/?([^/]*)/?([^/]*)/?$ ./Lesson.php?type=$1&data=$2 [NC,L]

I have the rules ordered so the if the url was foo.com/lesson/add/ then the first rule is matched, but this results in a 500 server error when I navigate to foo.com/lesson/ .

However, if I remove the question mark on the lesson line RewriteRule ^Lesson/([^/]*)/?([^/]*)/?$ ./Lesson.php?type=$1&data=$2 [NC,L] it works.

I need the final slash to be optional.

Problem is this regex:

 ^Lesson/?([^/]*)/?([^/]*)/?$

Which is causing infinite looping and causing 500 error since it matches /lesson/ as well as /Lesson.php . Change 2nd rule to this:

RewriteRule ^Lesson/([^/.]+)/([^/.]+)/?$ ./Lesson.php?type=$1&data=$2 [NC,L,QSA]

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