简体   繁体   English

网址重写:将mydomain.com/index.php更改为mydomain.com/home

[英]URL rewriting: Change mydomain.com/index.php to mydomain.com/home

I am working with PHP and I want to change this url mydomain.com/index.php to this mydomain.com/home so wrote the following code: 我正在使用PHP并且想将此URL mydomain.com/index.php更改为mydomain.com/home因此编写了以下代码:

RewriteEngine on
RewriteRule home index.php

When I go to mydomain.com/home it works but when I go to mydomain.com/index.php the url does not change to mydomain.com/home 当我转到mydomain.com/home它可以工作,但是当我转到mydomain.com/index.php ,URL不会更改为mydomain.com/home

How can I solve this problem, please ? 请问如何解决这个问题?

Try : 尝试:

RewriteEngine on
#externally redirect "/index.php" to "/home"
RewriteCond %{THE_REQUEST} \s/index\.php
RewriteRule ^ /home [L,R]
#internally map "/home" back to "/index.php"
RewriteRule home index.php

Example

RewriteEngine on
RewriteBase /
RewriteRule index.php http://example.com/home [L,R=301]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Heroku上将app.mydomain.com作为mydomain.com/app运行 - Run app.mydomain.com as mydomain.com/app on Heroku 使用PHP / Nginx将cookie域从无域迁移到.mydomain.com - Migrate cookie domain from no domain to .mydomain.com with PHP/Nginx Symfony 为 mydomain.com/parameter 创建路由 - Symfony create routing for mydomain.com/parameter PHP邮件未从mydomain.com发送到Google应用程序电子邮件myname@mydomain.com - PHP mail is not sending from mydomain.com to the google apps email myname@mydomain.com .htaccess www.mydomain.com/index.php?page=home到www.mydomain.com/home - .htaccess www.mydomain.com/index.php?page=home to www.mydomain.com/home Laravel 4.1使用301永久重定向将所有请求从www.mydomain.com重定向到mydomain.com - Laravel 4.1 Redirect all requests from www.mydomain.com to mydomain.com with 301 permanent redirect 如何在Codeigniter中使用mobiledetect.net将mydomain.com重定向到m.mydomain.com? - How to redirect mydomain.com to m.mydomain.com with mobiledetect.net in codeigniter? 如何使用zend框架获取像mydomain.com/username这样的动态URL - how to get dynamic URL like mydomain.com/username using zend framework 使用PHP设置“ mydomain.com/username”的任何简单,整洁的方法吗? - Any easy, noncluttering way to set up “mydomain.com/username” using PHP? 提交表单后,将数据插入Mysql并将用户重定向到URL mydomain.com/entries/last_inserted_id - After form submit, insert data into Mysql and redirect user to an url mydomain.com/entries/last_inserted_id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM