Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure redirection on apache server

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the apache server how to configure redirection, has a certain reference value, friends in need can refer to. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

What is redirection?

Reorient various network requests to other places through various methods (divided into internal and external, internal is invisible, external url will change)

This is an official introduction. In my own words, redirect is to send a network request to another place. You originally wanted to go to Xi'an, but the redirect sent you to Ya'an. That's the kind of consciousness.

What is the use of redirection?

What's the use of talking about it? when are we going to use redirection?

For example, now your website structure needs to be adjusted, you can access it by visiting music.jack.net in the past, but you can continue to visit it if you can't access it now.

Everyone who uses the ThinkPHP framework knows that we will have an .htaccess file, which is the configuration redirection rule. Let you visit yuns.com as if you are visiting yuns.com/index.php, here you can access it without typing index.php. If you delete the .htaccess file and type yuns.com, Apache will return the file that cannot be accessed

The above two examples are the use of redirection. Here we can draw the conclusion that the function of redirection is that the address requested by the network can be transferred to other places, which can be seen internally, not seen by users, or externally. For example, if your URL is changed, you can use external redirection. When users collect the address, they will collect the new URL.

Achieve redirection

There are three ways to achieve redirection

Create an .htaccess file

Create an .htaccess file in your project file. In the windows operating system, you cannot directly create a file that begins with [.]. We can create it in command line mode.

After entering the command line mode, change to the directory where you want to create the .htaccess file. Here I change to: d:\ wamp\ www\ and then type: echo 1 > .htaccess / / and the file is created successfully.

We open the .htaccess file and write the following in the file

RewriteEngine On # start rewriting RewriteRule ^ (. *)\ $test.html # rewrite rule (rule is a regular expression) # the configuration here is an example, which you can configure according to your project

Enter your project address in the address, and the server will be directed to the address you configured.

Httpd.conf configuration in Apache

Find AllowOverride None in the configuration and add the redirection rule below it. Write it correctly here. If you write it wrong, the Apache restart will fail.

AllowOverride None # here we do not need to rewrite permissions, we can close RewriteEngine On # and start rewriting RewriteRule ^ (. *)\ .html$ test.html # rewriting rules

Redirect in PHP

Since PHP is simple, here we use PHP to achieve redirection. Using PHP to redirect the url in the address bar will change, but the above two methods will not. It depends on whether your project is redirected externally or internally.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report