如何重定向为file.php到文件中,但要文件指向为file.php? [英] How to redirect file.php to file, but make file point to file.php?
问题描述
我试图用的mod_rewrite
在我的.htaccess文件清理我的网址。
比方说,我有我的服务器上的以下文件:
/about.php
/contact.php
如果用户键入关于
或联系人
,我想 about.php
或 contact.php
要显示给用户,但要确保网址保持不变(即这一切发生服务器端)。同样,如果用户输入 about.php
或 contact.php
,我希望它301重定向到关于
或联系人
,这将进而拉动网页服务器端,同时保持一个pretty的URL。
我已经试过到目前为止:
RewriteEngine叙述上
重写规则有关about.php
重写规则联系contact.php
重写规则about.php约[R]
重写规则contact.php接触[R]
这导致在一个圆形的重定向循环。
和其他方式轮:
RewriteEngine叙述上
重写规则about.php约[R]
重写规则contact.php接触[R]
重写规则有关about.php
重写规则联系contact.php
这是功能性的,但重定向不能正常工作(网址保持不变)。
我怎样才能让这个我没有得到一个重定向循环,但我的页面将全部指向版本,而的.php
?
注:我知道, [R]
是302不是301,但我使用302的测试的
RewriteEngine叙述上
的RewriteCond%{ENV:REDIRECT_STATUS} 200
重写规则。* - [L]
重写规则^高科技$ tech.php [L]
重写规则^接触$ contact.php [L]
重写规则^高科技\ .PHP $高科技[L,R]
重写规则^接触\ .PHP $接触[L,R]
I'm trying to clean up my URLs using mod_rewrite
in my .htaccess files.
Let's say I have the following files on my server:
/about.php
/contact.php
If a user types about
or contact
, I want about.php
or contact.php
to be displayed to the user, but ensuring the URL stays the same (i.e. it all happens server-side). Similarly, if the user enters about.php
or contact.php
, I want it to 301 redirect to about
or contact
, which will then pull the page server-side, whilst keeping a pretty URL.
What I have tried so far:
RewriteEngine on
RewriteRule about about.php
RewriteRule contact contact.php
RewriteRule about.php about [R]
RewriteRule contact.php contact [R]
That results in a circular redirect loop.
And the other way round:
RewriteEngine on
RewriteRule about.php about [R]
RewriteRule contact.php contact [R]
RewriteRule about about.php
RewriteRule contact contact.php
This is functional, but the redirect doesn't work (the URL stays the same).
How can I make it so that I don't get a redirect loop but my pages will all point to the version without .php
?
Note: I know that [R]
is 302 not 301 but I'm using 302 for testing.
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteRule ^tech$ tech.php [L]
RewriteRule ^contact$ contact.php [L]
RewriteRule ^tech\.php$ tech [L,R]
RewriteRule ^contact\.php$ contact [L,R]
这篇关于如何重定向为file.php到文件中,但要文件指向为file.php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!