当我请求我的网站时,我试图向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