问题
Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteBase /
RewriteRule ^haveg/employer/([0-9]+)/(.*) haveg/employer.php?msg_id=$1
It works fine when i use
http://localhost/haveg/employer/7003/the-message-title
or
http://localhost/haveg/employer/7003/
The problem is here http://localhost/haveg/employer/7003
because i removed the forward slash at the end. it gives page not found error.
回答1:
RewriteRule ^haveg/employer/([0-9]+)/?(.*) haveg/employer.php?msg_id=$1
I think adding a questionmark should allow it to match.
回答2:
Try changing your last line to
RewriteRule ^haveg/employer/([0-9]+)([^0-9]*) haveg/employer.php?msg_id=$1
This should accept both cases.
回答3:
I suggest you add another RewriteRule
to make your intention clear. In this code the first rule handles the case when the URL ending with digits followed by an optional slash (when the msg_id
query field is blank), and the second applies where there is a message following the digits.
RewriteRule ^haveg/employer/([0-9]+)/?$ haveg/employer.php?msg_id=
RewriteRule ^haveg/employer/([0-9]+)/([^/]+)$ haveg/employer.php?msg_id=$1 [L]
来源:https://stackoverflow.com/questions/9066747/redirect-using-mod-rewrite