2013-10-08 104 views
1

我需要一些帮助改写以下网址的:htaccesss重写将无法正常工作

example.com/news/top/2/

example.com/news/top/

这是我目前的.htaccess文件

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/\.]+)/([^/\.]+) index.php?view=$1&task=$2 
RewriteRule ^news/([^/\.]+)/([0-9]+) index.php?view=news&task=$1&page=$2 [L] 
RewriteRule ^news index.php?view=news 

我认为这会工作,但每当我访问= example.com/news/top/2/ 我尝试呼应了$ _GET [“页”]它说,变量是没有定义的。

somone pleas可以帮助解决这个神经断裂问题吗?

回答

2

确保使用端锚$

RewriteEngine on 

## If the request is for a valid directory 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
## If the request is for a valid file 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
## If the request is for a valid link 
RewriteCond %{REQUEST_FILENAME} -l 
## don't do anything 
RewriteRule^- [L] 

RewriteRule ^news/([^/.]+)/([0-9]+)/?$ index.php?view=news&task=$1&page=$2 [L] 
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?view=$1&task=$2 [L] 
RewriteRule ^news/?$ index.php?view=news [L] 
+1

谢谢你这个工作。 – rokkz

+0

@rokkz:很高兴知道它为你工作。 – anubhava

1

这条规则:

RewriteRule ^([^/\.]+)/([^/\.]+) index.php?view=$1&task=$2 

需要$

RewriteRule ^([^/\.]+)/([^/\.]+)$ index.php?view=$1&task=$2 

,因为它匹配不仅仅是/dir1/dir2