使用.htaccess重定向旧链接

时间:2014-01-02 18:09:32

标签: .htaccess mod-rewrite

在我的Joomla 2.5网站上,我重命名了......

http://www.my-site.com/old-link.html

用于SEO性能

http://www.my-site.com/new-link.html

旧网址列在Google上。如何301将重定向/重写点击重定向到新网址?

这是我当前的.htaccess,包括SEF链接,并将非www重写为www:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F,L]

RewriteCond %{HTTP_HOST} ^my-site.com$ [NC]
RewriteRule ^(.*)$ http://www.my-site.com/$1 [R=301,L]

RewriteBase /

## Begin - Joomla! core SEF Section.
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

# take care of sitemap.xml
RewriteCond %{REQUEST_URI} ^/sitemap.xml
RewriteRule .* /index.php?option=com_xmap&view=xml&tmpl=component&id=1&format=html [L]

1 个答案:

答案 0 :(得分:2)

您需要在顶部(RewriteEngine On行下方)添加此内容:

RewriteRule ^old-link\.html$ /new-link.html [L,R=301]