开发者

Rewriting from a SEO friendly URL to another SEO friendly URL on the same site

开发者 https://www.devze.com 2023-03-26 00:17 出处:网络
For our SEO needs in my company, we need to change some SEO URLs to another开发者_开发知识库 ones through 301.

For our SEO needs in my company, we need to change some SEO URLs to another开发者_开发知识库 ones through 301.

Example:

/seo/keywords-1-2-3/ to /seo/mynew301page-1-2-3/

Is there some Apache rewrite rule that I can specify that certain URLs should be redirected to the new one?


As simple as this:

Redirect 301 /seo/keywords-1-2-3/ /seo/mynew301page-1-2-3/

The above will redirect ALL requests for URLs that start with /seo/keywords-1-2-3/ to /seo/mynew301page-1-2-3/. For example: /seo/keywords-1-2-3/something?say=hello ==> /seo/mynew301page-1-2-3/something?say=hello

If it has to be precise match (only /seo/keywords-1-2-3/ and not /seo/keywords-1-2-3/something, then use this one:

RedirectMatch 301 ^/seo/keywords-1-2-3/$ /seo/mynew301page-1-2-3/

The same, but using mod_rewrite:

RewriteEngine On

# broad (base) match
RewriteRule ^/seo/keywords-1-2-3/(.*)$ /seo/mynew301page-1-2-3/$1 [R=301,L]

# exact match
RewriteRule ^/seo/keywords-1-2-3/$ /seo/mynew301page-1-2-3/ [R=301,L]


You can do it n two ways:

  1. .htaccess
  2. httpd.conf

Mostly the .htaccess configuration method is used.

So you can use this code in your .htaccess file:

RewriteEngine On
RewriteRule ^/seo/keywords-1-2-3/ /seo/mynew301page-1-2-3/ [R=301,L]
0

精彩评论

暂无评论...
验证码 换一张
取 消