Redirect
| Introduction | |
| How to make a redirect | |
| How to Make Multiple Redirects | |
| Addressing problems |
Introduction
Before redirecting, you need to find out the type of server on which
Your website is hosted.
File. .htaccess Making changes to the Apache server
In Nginx, a file serves a similar purpose.
nginx.conf It's the same thing, but the syntax is a little different.
Simple Permanent Redirect 301
To move the page from one address to another permanently put in .htaccess the following changes:
RewriteEngine on
Redirect 301 old_url http://new_page_address
Where old url is the address of old page relative root site
If your server is Apache, a file
.htaccess You don't.
You can create it yourself and place it, for example.
The root directory.
Example
RewriteEngine on
Redirect 301 /old_dir/url1.php /new_dir/url1.php
Redirect 301 /old_url1.php /new_url.php
Redirect 301 /old_url2.php /new_dir/new_url.php
You can redirect an entire directory.
RewriteEngine on
Redirect 301 /old_dir /new_dir
Two redirects
If you make two redirects that affect a page, For example, you redirect an entire directory, and you also change something inside. You need to do it carefully.
Suppose it were:
/old_dir/a.php
/old_dir/b.php
/old_dir/c.php
Now we need to:
/new_dir/a.php
/new_dir/b.php
/new_dir/new_c.php
For forwarding a.php and b.php rule
Redirect 301 /old_dir /new_dir
And here's to redirect correctly.
c. php into new_c.php
Think about where the old one is going.
c. php
considering our redirect Redirect 301 /old_dir /new_dir
As you may have guessed, it will be redirected from
/old_dir/c.php
into
/new_dir/c.php
And now this non-existent
/new_dir/c.php
We need to redirect to
/new_dir/new_c.php
Therefore, the rule will look as follows:
Redirect 301 /old_dir /new_dir
Redirect 301 /new_dir/c.php /new_dir/new_c.php
Debage
If you have any problems with redirecting, the first thing you do is
I advise you to go to the hosting and honor the logs.
Hosting.
Beget
which I use, and I can recommend - logs with errors
file access
sitename.xx.error.log
When I want to check what’s wrong, I’ll log in to the hosting service.
ssh
I go to public html and do it.
tail -n 100 aredel.com.error.log
This is how I see the last 100 lines of today's log. And if there were
… script '/home/xxx/aredel.com/public_html/new_dir/c.php' not found or unable to start, referer heihei.ru
I would understand that there is no redirect from the old c.php new new_c.php and add a line
Redirect 301 /new_dir/c.php /new_dir/new_c.php
In .htaccess
Read more about working with logs
In my article about testing
I also advise you to study commands.
Bash
Robots:
207.46.13.56 bing
Related Articles:
Article author: Andrei Olegovich
| Web | |
| IP | |
| HTML | |
| CSS | |
| Network mask | |
| JavaScript | |
| PHP | |
| NodeJS | |
| NPM | |
| Gulp | |
| URLencode | |
| Which hosting to choose | |
| PUT vs POST | |
| Flask | |
| Django |