php - How to write a 301 redirect to the corresponding page in the .htaccess file
PHP中文网
PHP中文网 2017-05-27 17:43:41
0
1
845

This is a better new domain name for the website. The previous one was http://www.baidu.com
Then it was changed to https://www.segmentfault.com
Why did it happen when I wrote 301 jump? fail?
My .htaccess file code is as follows

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.segmentfault.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^baidu.com [NC]
RewriteRule ^(.*)$ https://www.segmentfault.com/ [L,R=301]
</IfModule>

This rule was previously used baidu.com/category/p123.html
Jump to www.baidu.com/category/p123.html
There is no problem

This is the writing rule corresponding to the server conf
New domain name

<VirtualHost *:443>
    ServerAdmin baidu@qq.com 
    DocumentRoot "/data/wwwroot/default/"
    ServerName www.segmentfault.com
    ErrorLog "/data/wwwlogs/www.segmentfault.com_error_apache.log"
    CustomLog "|/usr/local/cronolog/sbin/cronolog /data/wwwlogs/segmentfault/pc/%Y%m%d_www.segmentfault.com_access.log" common
<Directory "/data/wwwroot/default">
    SetOutputFilter DEFLATE
    Options FollowSymLinks ExecCGI
    Require all granted
    AllowOverride All
    Order allow,deny
    Allow from all
    DirectoryIndex index.html index.php
</Directory>
</VirtualHost>

conf rules for old domain names

<VirtualHost *:80>
    ServerAdmin baidu@qq.com
    DocumentRoot "/data/wwwroot/default"
    ServerName www.baidu.com
    ErrorLog "/data/wwwlogs/www.baidu.com_error_apache.log"
    CustomLog "|/usr/local/cronolog/sbin/cronolog /data/wwwlogs/baidu/pc/%Y%m%d_www.baidu.com_access.log" common
<Directory "/data/wwwroot/default">
    SetOutputFilter DEFLATE
    Options FollowSymLinks ExecCGI
    Require all granted
    AllowOverride All
    Order allow,deny
    Allow from all
    DirectoryIndex index.html index.php forum.php
</Directory>
</VirtualHost>
这些都是设置好之后,我访问老域名http://www.baidu.com/category/p1056.html
为什么始终跳转到https://www.segmentfault.com/
不管访问什么页面都是跳转到https://www.segmentfault.com/
怎么样才可以让他跳转到对应的页面也就是访问http://www.baidu.com/category/p1056.html
能够跳转到https://www.segmentfault.com/category/p1056.html
哪里设置不对了,。求解
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
大家讲道理

RewriteRule . / [L]这句话, 注意参数 L means last, which will stop the rewriting operation immediately and no other rewriting rules will be applied.

All subsequent rules will be invalid.

Redirect RewriteRule ^(.*)$ https://www.segmentfault.com/ [R=301,L]This sentence is correct.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!