2017-11-17 247 views
0

我想重写规则我的网址是这样的:重写规则的htaccess的犯规工作和错误500显示

https://mywebsite.com/dev/index.php?controller=pages&action=inscription

https://mywebsite.com/dev/inscription

对于此刻我的htaccess的文件包含此说明:

RewriteEngine On 
RewriteRule ^([^/]*)/([^/]*)$ /dev/index.php?controller=$1&action=$2 [L] 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /dev/index.php?controller=$1&action=$2&id=$3 [L] 

的2个RewritRules此URLS的工作原理:

/dev/index.php?controller=sport&action=accueil --->/dev/sport/accueil /dev/index.php?controller=sport&action=produit&id=1 --->/dev/sport/produit/1

这里的特异性是在那些对值的所有控制器指定, “网页”,一个RewriteUrl像这样,但让我错误500:

RewriteRule ^([^/]*)$ /dev/index.php?controller=pages&action=$1 [L] 

非常感谢您的帮助,如果您需要更多的细节,请留下评论。

回答

0

这条规则似乎是这个问题:

RewriteRule ^([^/]*)$ /dev/index.php?controller=pages&action=$1 [L] 

这是导致无限循环,因为图案[^/]*是匹配重写的URI /index.php为好。

插入略低于RewriteEngine On线这条规则跳过所有文件&目录:

RewriteEngine On 

# skip all files and directories from rewrite rules below 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 

# all your rewrite rules go below this 

还要注意的是,如果你的.htaccess里面/dev/目录,那么你可以在目标如使用index.php代替/dev/index.php

RewriteRule ^([^/]*)$ index.php?controller=pages&action=$1 [L,QSA] 
+0

这工作正常吗? – anubhava