![](/img/trans.png)
[英]How to change example.com/index.php/lib to example.com/lib?
[英]Change example.com/dashboard.php to example.com/index.php?action=dashboard
我想从以下更改我的站点页面URL:
mysite.com/profile.php
至
mysite.com/index.php?action=profile
哪种语言适用于此? 我尝试了一堆.htacesss
代码,但似乎没有任何效果! 任何.htacess
建议?
我的代码:
RewriteEngine On
RewriteRule ^profile.php(.+)$ /index.php?action=$1 [L]
为什么不只将重定向代码放在index.php上,以便如果存在$ _GET ['action']变量并指向'profile',您将被重定向到profile.php?
否则,我相信.htaccess是解决重定向/ URL重写所必须使用的。
将此放在您index.php页面的顶部...
<?php
if ($_GET['action'] == "profile") {
echo "<meta http-equiv='refresh' content='0; url=profile.php' />";
}
?>
另外,请检查一下。 http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/
使用htaccess重定向通常是用另一种方式,当我们想使用干净的URL时,没有其他方式可以正常工作,但当然是可能的。 我同意@ScottCarmichael的观点,如果您使用的是querystrings PHP,则if语句(或switch)是一个很好的解决方案(但我更喜欢使用usin listener hearder()
函数,而不是refresh),那么可以在顶部使用PHP脚本包含一个include在所有条件下。
如果您仍然认为htaccess是适合您的方法,请尝试以下操作:
RewriteEngine on
RewriteRule ^profile.php$ index.php?action=profile [R,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.