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:
- .htaccess
- 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]
精彩评论