我正在使用以下代码获得良好结果,以便在不指定扩展名的情况下访问我的php文件alla到/ it目录。换句话说,我可以访问“http://www.mydomain.com/it/about.php”只需写下“http://www.mydomain.com/it/about “
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://www.mydomain.com/it/$1.php [L]
当我尝试访问http://www.mydomain.com/it/question_answers.php时也是如此。 如何直接访问*“http://www.mydomain.com/it/question_answers.php”*还要写“http://www.mydomain.com/it/question-answers”? 我在前面写下了floowing代码,但似乎没有用。
Redirect 301 /question-answer http://www.mydomain.com/it/question_answer.php
因为如果我写“http://www.mydomain.com/it/question-answer”,浏览器会尝试打开页面: “http://www.mydomain.com/it/question-answer.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php。 php.php.php.php.php“
帖子的一个小摘要:
谢谢!
答案 0 :(得分:0)
这应该适合你:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://www.mydomain.com/$1.php
RewriteRule it/question-answer\.php http://www.mydomain.com/it/question_answer.php [R=301,L]
我更改了两件事:我在第一个RewriteRule的新网址中删除了it/
。否则,您将被重定向到it/it/
我还在第二个RewriteRule中添加了\.php
。我真的不知道为什么,但RewriteRule似乎取代了模式而不是重定向。如果您的模式为it/question-answer
且真实网址为it/questions-answer.php
,则.php
将不会被替换。