的.htaccess特定URL不同的端口

编程入门 行业动态 更新时间:2024-10-25 19:37:32
本文介绍了的.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不同的端口

本文发布于:2023-08-07 19:48:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1321414.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   htaccess   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!