2012-01-30 53 views
-1
Options +FollowSymLinks 
Options +Indexes 
RewriteEngine on 
RewriteBase/
RewriteRule ^haveg/employer/([0-9]+)/(.*) haveg/employer.php?msg_id=$1 

当我使用重定向使用mod_rewrite

http://localhost/haveg/employer/7003/the-message-title 
or 
http://localhost/haveg/employer/7003/ 

的问题是在这里http://localhost/haveg/employer/7003因为我删除末尾的斜杠它工作正常。它给页面找不到错误。

回答

2

重写规则^ haveg /雇主/([0-9] +)/?(。*)haveg/employer.php?MSG_ID = $ 1

我想添加一个问号,应该允许它相匹配。

+0

谢谢它的作品:) – shaikh 2012-01-30 16:03:56

+0

所以我可以得到一个漂亮的绿色复选标记? :) – Gus 2012-01-30 16:07:42

+0

这将重写URL http:// localhost/haveg/employer/7003message到'http://localhost/employer.php?msg_id = message'。不是很干净 – Borodin 2012-01-30 16:14:30

0

试着改变你的最后一行

RewriteRule ^haveg/employer/([0-9]+)([^0-9]*) haveg/employer.php?msg_id=$1 

这应该接受这两种情况。

0

我建议你再添加一个RewriteRule以使你的意图清晰。在此代码中,第一条规则处理以数字后跟可选斜杠结尾的URL(当msg_id查询字段为空时),第二条规则适用于数字后面有消息的情况。

RewriteRule ^haveg/employer/([0-9]+)/?$ haveg/employer.php?msg_id= 
RewriteRule ^haveg/employer/([0-9]+)/([^/]+)$ haveg/employer.php?msg_id=$1 [L]