I am adding some rewrite rules to my htaccess file for news articles and eventdetails so i can embed the title in the url, but when i set the 'folder' name the same as the original page, it does not work. When the 'folder' name is different, it works fine
working htaccess file is like this...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite for eventdetail.php?EventID=1&EventName=event-name
RewriteRule ^event/([0-9]+)*$ eventdetail.php?EventID=$1 [NC,L]
RewriteRule ^event/([0-9]+)/([0-9a-zA-Z_-]+)*$ eventdetail.php?EventID=$1&EventName=$2 [NC,L]
so, for example, if I use ^event/...
my url is sitename/event/id/eventname and this works ok,
but if I use ^eventdetail/...
my url is sitename/eventdetail/id/eventname and this fails, the get parameter for the event id is not passed
答案 0 :(得分:1)
您应该稍微改写一下规则来处理这两个规则。部分问题可能是多视图,说明为什么你不能使用文件名。把它关掉。另外我还会使尾随斜杠可选。
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrite for eventdetail.php?EventID=1&EventName=event-name
RewriteRule ^event/([0-9]+)/([0-9a-zA-Z_-]+)/?$ eventdetail.php?EventID=$1&EventName=$2 [NC,L]
RewriteRule ^event/([0-9]+)/?$ eventdetail.php?EventID=$1 [NC,L]