[英]Change example.com/dashboard.php to example.com/index.php?action=dashboard
I would like to change my site page URLs from the following: 我想从以下更改我的站点页面URL:
mysite.com/profile.php
to 至
mysite.com/index.php?action=profile
What language would work for this? 哪种语言适用于此? I tried a bunch of
.htacesss
codes but none seem to work! 我尝试了一堆
.htacesss
代码,但似乎没有任何效果! Any .htacess
suggestions? 任何
.htacess
建议?
My code: 我的代码:
RewriteEngine On
RewriteRule ^profile.php(.+)$ /index.php?action=$1 [L]
Why not just put redirect code on index.php so that if a $_GET['action'] variable exists and points to 'profile' you'll be redirected to profile.php? 为什么不只将重定向代码放在index.php上,以便如果存在$ _GET ['action']变量并指向'profile',您将被重定向到profile.php?
Otherwise I believe .htaccess is what you're going to have to use to address this redirection/URL rewrite. 否则,我相信.htaccess是解决重定向/ URL重写所必须使用的。
Put this at the top of you index.php page... 将此放在您index.php页面的顶部...
<?php
if ($_GET['action'] == "profile") {
echo "<meta http-equiv='refresh' content='0; url=profile.php' />";
}
?>
Also, check this out. 另外,请检查一下。 http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/
http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/
Using htaccess redirects is ususaaly used the other way, when we want to have clean URL'S , didnt see much that work the other way but it is of course possible. 使用htaccess重定向通常是用另一种方式,当我们想使用干净的URL时,没有其他方式可以正常工作,但当然是可能的。 I agree with @ScottCarmichael that if you are working with querystrings PHP if statement (or switch) is a good solution (but i prefere usin
hearder()
function rather than refresh ) , then you can have an include on the top with a PHP script with all conditions. 我同意@ScottCarmichael的观点,如果您使用的是querystrings PHP,则if语句(或switch)是一个很好的解决方案(但我更喜欢使用usin listener
hearder()
函数,而不是refresh),那么可以在顶部使用PHP脚本包含一个include在所有条件下。
If you still think htaccess is the way for you, try this: 如果您仍然认为htaccess是适合您的方法,请尝试以下操作:
RewriteEngine on
RewriteRule ^profile.php$ index.php?action=profile [R,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.