重定向的.htaccess只网址中包含月底号 [英] .htaccess redirect only URLs contain number at end
本文介绍了重定向的.htaccess只网址中包含月底号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要重定向的URL每包含端子号:
http://example.com/773到http://blog.example.com/773
而不是重定向的URL包含这样的字符串:
http://example.com/web或http://example.com/web/shop或http://example.com/about
我使用这个htaccess的code:
< IfModule mod_rewrite.c>
RewriteEngine叙述在
的RewriteCond%{REQUEST_URI} ^ / [0-9]
重写规则(。*)http://blog.example.com/$1 [R = 301,L]
< / IfModule>
但这种htaccess的code重定向的URL是这样的:
http://example.com/773到http://blog.example.com/blog/773
解决方案
下面的规则将只重定向这类URL的只有: http://example.com/773
。如果URL就会像 http://example.com/somfolder/773
(与路径中的一些文件夹),那么什么都不会发生了。
RewriteEngine叙述在
的RewriteBase /重写规则^(\\ d +)$ http://blog.example.com/$1 [R = 301,L]
I want to redirect every URLs contain number at end to subdomain :
http://example.com/773 to http://blog.example.com/773
and not redirect URLs contain strings like this :
http://example.com/web or http://example.com/web/shop or http://example.com/about
i used this htaccess code :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/[0-9]
RewriteRule (.*) http://blog.example.com/$1 [R=301,L]
</IfModule>
but this htaccess code redirect URLs like this :
http://example.com/773 to http://blog.example.com/blog/773
解决方案
The rule below will redirect ONLY this sort of URLs only: http://example.com/773
. If URL will be like http://example.com/somfolder/773
(with some folder in the path) then nothing will happened.
RewriteEngine On
RewriteBase /
RewriteRule ^(\d+)$ http://blog.example.com/$1 [R=301,L]
这篇关于重定向的.htaccess只网址中包含月底号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文