简体   繁体   English

使用.htaccess重写URL

[英]rewriting a URL using .htaccess

Good morning, I want to create a simple URL which changes a certain URL from let's say index.php to "home", to accomplish this I wrote the code below and saved it as a .htaccess file 早上好,我想创建一个简单的URL,将某个URL从例如index.php更改为“ home”,为完成此操作,我在下面编写了代码并将其保存为.htaccess文件

RewriteEngine on

RewriteRule ^home/?$ index.php [NC,L]

But all this code does is make it possible for a user to access the home page by simply typing the websites name/home but when the user follows a link the URL still shows index.php, how can I go about solving this? 但是,所有这些代码的作用是使用户只需键入网站名称/首页即可访问主页,但是当用户单击链接时,URL仍显示index.php,我该如何解决呢?

You have to change the href of the corresponding a tags from index.php to home . 您必须将相应a标签的href将从index.php更改为home

They are called symbolic links and is used for representation. 它们称为符号链接 ,用于表示。 Still the content is available via direct url. 内容仍然可以通过直接url获得。

or add the below code in your php page. 或在您的php页面中添加以下代码。

if(strpos($_SERVER['REQUEST_URI'],$_SERVER["SCRIPT_FILENAME"])===true)
    header('location:home');

This will redirect people from the current page to home if they directly visited the page 如果人们直接访问了该页面,这会将他们从当前页面重定向到home

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM