mod_rewrite rule not working

試著忘記壹切 提交于 2020-01-04 05:46:27

问题


I have the following rules in my htaccess:

RewriteRule ^([^/.]+)/?$ list.php?categoryShortForm=$1&locationShortForm=world      [QSA]
RewriteRule ^([^/.]+)/([^/.]+)/?$ list.php?categoryShortForm=$1&locationShortForm=$2    [QSA]
RewriteRule ^([^/.]+)/([^/.]+)/[^/.]*-p([0-9]+)/?$ view.php?categoryShortForm=$1&locationShortForm=$2&postingId=$3  [QSA]

In my localhost (windows, xampp), it all works fine. In my real server (linux, apache) the first 2 rules work fine, but not there 3rd one.

For example:

/plastic-surgery/california-usa/ works fine, but /plastic-surgery/los-angeles-california-usa/test-1-p1 gives me a 404

Any idea??


回答1:


Check to make sure that you can browse directly to the target URLs. If mod_rewrite is rewriting onto something that doesn't exist, you'll get that 404. It might help to ratchet up mod_rewrite's log level to a high value, so you can see what it's rewriting to.




回答2:


I am a little unclear on how your working URL is supposed to actually work. All three of your patterns start with "one or more non-slash, non-period characters" ([^/.]+), but URLs going into the pattern matching start with slashes: "/plastic-surgery/california-usa/".

Have you turned on mod_rewrite logging and checked out what mod_rewrite is actually doing?

  RewriteLog "/tmp/rewrite.log"
  RewriteLogLevel 9


来源:https://stackoverflow.com/questions/1704503/mod-rewrite-rule-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!