2017-11-17 246 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