當我請求我的網站時,我試圖向URL添加尾部斜線,然後使用mod_rewrite將其作爲參數傳遞給index.php。mod_rewrite添加尾部斜線並傳遞給index.php
我的.htaccess文件看起來像這樣:
RewriteEngine On
#Add trailing slash
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [R]
#Pass to index.php
RewriteRule ^(.*)/$ index.php?p=$1
在我的index.php文件只輸出參數:
<?php echo $_GET["p"]; ?>
但是當我輸入的地址欄中除了http://mydomain.com/,例如http://mydomain.com/contact,php始終輸出http://mydomain.com/index.php
。所以http://mydomain.com/index.php
在某種程度上作爲參數,而不是請求的頁面,如contact
過去了,但我不知道爲什麼......
此外,當我編輯
RewriteRule ^(.*)/$ index.php?p=$1
到
RewriteRule ^(.*)/$ /index.php?p=$1
和我鍵入網址例如mydomain.com/contact
Apache給我302找到並找到它被移動到的位置的鏈接,但它鏈接到同一頁面...
任何想法?
謝謝。
「如果尾隨斜槓]丟失,服務器轉儲錯誤:」你說的肯定是Windows服務器,因爲Linux下這兩種情況下是相同的:'cd/home' =='cd/home /'(對於URL也是一樣的) – feeela 2012-07-27 14:19:26
我用'DirectorySlash Off'指令關閉了自動shash添加,但是重寫仍然不起作用。 。 – longaster 2012-07-27 14:26:56