apache achieve 301 permanent redirect method

Source: Internet
Author: User
Tags .com domain name .url access apache blog code domain domain name

Because the blog is used as a blog www.jzread.com domain name, so want to achieve all jzread.com redirect (jump) to www.jzread.com. At the same time in accordance with the recommendations of Google, the use of server-side 301 redirect, in order to ensure that users and search engines to the correct page the best way. 301 status code indicates that a web page has been permanently migrated to a new location. The following will find out about apache 301 permanent redirect 2 methods, you need to have access to the server's. Htaccess file permissions.

Apache module mod_alias the Redirect and RedirectMatch command

The two commands mentioned above are used in a similar way. The difference is that the latter RedirectMatch based on the regular expression matching the current URL to send an external redirect syntax is:

Redirect [status] URL-path URL

RedirectMatch [status] regex URL

The status parameter can use the following HTTP status code:

permanent

Returns a permanent redirect status code (301) indicating that the location change for this resource is permanent.

temp

Returns a temporary redirect status code (302), which is the default.

seeother

A "see" status code is returned (303) indicating that this resource has been replaced.

gone

An "obsolete" status code is returned (410) indicating that this resource has been permanently deleted. If you specify this status code, the URL parameters will be ignored.

Example:

APACHE

Redirect 301 /old/old.htm http://www.jzread.com/new.htm
Redirect permanent / one http://jzread.com/two
RedirectMatch 301 (. *). Gif $ http://www.jzread.com/images/$1.jpg


Use mod_rewrite to rewrite the URL

APACHE

Options + FollowSymLinks
RewriteEngine on
RewriteCond% {HTTP_HOST} ^ jzread.com
RewriteRule ^ (. *) $ Http://www.jzread.com/$1 [R = permanent, L]


Here to determine the current server variable HTTP_HOST is equal to jzread.com, to really rewrite, permanent redirection according to R = permanent, L said and immediately stop rewriting, and no longer apply other rewrite rules

Here's my final implementation of the .htaccess file, which also incorporates wordpress rewrite rules.

APACHE

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
#Redirect
Options + FollowSymLinks
RewriteCond% {HTTP_HOST} ^ jzread.com $
RewriteCond% {HTTP_HOST}! ^ $
RewriteRule ^ (. *) $ Http://www.jzread.com/$1 [R = 301, L]
#Rewrite (blog)
RewriteCond% {REQUEST_FILENAME}! -f
RewriteCond% {REQUEST_FILENAME}! -d
RewriteRule ^ blog /.* /blog/index.php [L]
RewriteRule. -
</ IfModule>
# END WordPress


Article source: jzread.com

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.