简体   繁体   English

将example.com/dashboard.php更改为example.com/index.php?action=dashboard

[英]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.

相关问题 如何将example.com/index.php/lib更改为example.com/lib? - How to change example.com/index.php/lib to example.com/lib? 使用,htaccess将example.com?id=12重定向到example.com/index.php?id=12 - using ,htaccess redirect example.com?id=12 to example.com/index.php?id=12 是否可以将 example.com/index.php?page=abc 重定向到 example.com/abc? - Is it possible to redirect the example.com/index.php?page=abc to example.com/abc? 如何将example.com/forum/index.php重定向到example.com/forum/ - How to redirect example.com/forum/index.php to example.com/forum/ 如何从这个example.com/index.php?lang=en更改我的多语言网址到这个example.com/en/? - How can I change my multilingual urls from this example.com/index.php?lang=en to this example.com/en/? “ example.com/index.php/page/about/”是好的做法吗? - Is “example.com/index.php/page/about/” good practice? Ubuntu-如何直接将example.com/opencart/index.php定向到http://example.com/和www.example.com? - Ubuntu - How direct example.com/opencart/index.php to http://example.com/ and www.example.com? 如何使用.htaccess将http://example.com/test.php设置为http://example.com/index.php?do=test? - How to make http://example.com/test.php to http://example.com/index.php?do=test using .htaccess? 不需要来自 example.com/{lang}/index.php 的 index.php - Not needing index.php from example.com/{lang}/index.php 如果网址中没有index.php,example.com / index.php中的首页无法加载 - Home page is not loading without index.php in url, example.com/index.php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM