2017-09-24 16 views
0

我想重定向一个子目录到一个子域,但我必须维护站点地图的端点。重定向301,除非当一个字符串是存在于URL与htaccess

我需要的是:

Redirect 301 /ru/ https://ru.mydomain.com 
#Exclude *sitemap* 

这类网址无法重定向:

https://www.mydomain/ru/sitemap.xml 
https://www.mydomain/ru/sitemap.1.xml 
https://www.mydomain/ru/sitemap.3.xml 
https://www.mydomain/ru/sitemap_ru.xml 

所有有网站地图串,我需要在网站地图字是网址中没有被重定向。 希望可以帮助我,因为我花了很多时间试图修复它没有运气。

我需要这样的:

{if *sitemap* is not present} 
Redirect 301 /ru/ https://ru.mydomain.com 
{/if} 

谢谢!

+0

什么是apache版本? –

回答

0

这个应该适合你。如果您的网站(www.mydomain)上的URL以/ ru开头,但不以/ ru/sitemap开头......我们将(301)重定向到https://ru.mydomain.com/,但路径中没有/ ru。例如https://www.mydomain/ru/news进入https://ru.mydomain.com/news

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^www\.mydomain$ [NC] 
RewriteCond %{REQUEST_URI} ^/?ru(/.*)?$ [NC] 
RewriteCond %{REQUEST_URI} !^/?ru/sitemap.*$ [NC] 
RewriteRule ^/?ru(/(.*))?$ https://ru.mydomain.com/$2 [R=301,L] 

的NC标志意味着这是不区分大小写的。 您需要mod_rewrite安装结束启用!