开发者

Redirect from old indexed pages with url rewrite

开发者 https://www.devze.com 2023-03-26 19:19 出处:网络
I have some old indexed pages in Google that need to be redirected to their new locations. Example: Google shows wwww.domain.com/pages/subpages/pag开发者_运维问答e.php that is now in www.domain.com/pa

I have some old indexed pages in Google that need to be redirected to their new locations. Example: Google shows wwww.domain.com/pages/subpages/pag开发者_运维问答e.php that is now in www.domain.com/pages/page.php.

I also need, when someone clicks on the old page in Google, to open rewritten URL. Example: User clicks on wwww.domain.com/pages/subpages/page.php, it will open him wwww.domain.com/pages/page.php, but with www.domain.com/page in address bar (without "pages/" and php extension).

So I have written this .htaccess code

Redirect 301 /pages/subpages/page.php http://www.domain.com/page
RewriteEngine On
RewriteRule ^page/?$ /pages/page.php 

The redirect works, but user have in address bar full URL (http://www.domain.com/pages/page.php), not the rewritten one(http://www.domain.com/page). It looks like the mod_rewrite doesn't work with redirect or something.

Is there any solution?


This code works fine for me:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# 301 redirect
RewriteRule ^pages/subpages/page\.php$ http://www.domain.com/page [R=301,L]

# rewrite
RewriteRule ^page/?$ /pages/page.php [L]

Please ensure that you have no other redirects/rewrites in your htaccess file as they may may perform additional rewrite/redirect actions.

0

精彩评论

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