的.htaccess特定URL不同的端口 [英] .htaccess specific URL to different port
本文介绍了的.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://%{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网址
http://www.mysite.com/page1
将重定向到
http://www.mysite.com/page1/
但
2 - 网址
http://www.mysite.com/some-prefix/page2
将重定向到
http://www.mysite.com: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/(.*[^/])/?$ http://www.mysite.com: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://%{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不同的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文