本文介绍了的.htaccess特定URL不同的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想一些重定向URL到不同的端口。我的.htaccess是:
I want redirect some URLs to a different PORT. My .htaccess is:
RewriteEngine on RewriteCond %{REQUEST_URI} !^(.*)/$ RewriteCond %{REQUEST_URI} !^(.*)(\.)(.*)$ RewriteRule ^(.*)$ %{HTTP_HOST}%{REQUEST_URI}/ [R=301,L]
我需要添加一个规则,重定向与^ some- preFIX所有请求/之初到8080端口,例如:
I need to add a rule that redirects all requests with ^some-prefix/ at the beginning to port 8080, example:
1网址
www.mysite/page1
将重定向到
www.mysite/page1/
但
2 - 网址
www.mysite/some-prefix/page2
将重定向到
www.mysite:8080/some-prefix/page2/
我怎样才能做到这一点?谢谢
How can I do this? Thanks
推荐答案您可以做这样
RewriteEngine on # redirect to 8080 if current port is not 8080 and "some-prefix/" is matched RewriteRule ^some-prefix/(.*[^/])/?$ www.mysite:8080/some-prefix/$1/ [R=301,L] # redirect with trailing slash if not an existing file and no trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !/$ RewriteRule ^(.*)$ /$1/ [R=301,L]
编辑:新的code。考虑您的意见考虑进去。
new code taking your comment into consideration
RewriteEngine on # redirect to 8080 if "some-prefix/" is matched RewriteCond %{SERVER_PORT} !^8080$ RewriteRule ^some-prefix/(.*[^/])/?$ %{HTTP_HOST}:8080/some-prefix/$1/ [R=301,L] # redirect with trailing slash if not an existing file and no trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !/$ RewriteRule ^(.*)$ /$1/ [R=301,L]更多推荐
的.htaccess特定URL不同的端口
发布评论