开发者

how do I redirect from a subdirectory to another directory, but strip off the original subdirectory from the URI using mod_rewrite

开发者 https://www.devze.com 2022-12-25 00:35 出处:网络
I have a Ruby on Rails app running on 12001. I am currently redirecting a subdomain to 127.0.0.1:12001 using some ReWriteCond detection.

I have a Ruby on Rails app running on 12001. I am currently redirecting a subdomain to 127.0.0.1:12001 using some ReWriteCond detection. Now I want to redirect my subdirectory to that rails app.

http[s]://domain.com/redmine

to

127.0.0.1:12001

The current rules apply REQUEST_URI to the above rails path, but I need to strip "/redmine" from the front of REQUEST_URI...开发者_StackOverflow

Any ideas?


You can do this without mod_rewrite.

Redirect Permanent /redmine http://127.0.0.1:12001

This should do what you want.


RewriteRule ^/redmine/(.*)$ http://127.0.0.1:12001/$1 [QSA,L]

If the rule is placed in the Directory directive, then:

RewriteRule ^redmine/(.*)$ http://127.0.0.1:12001/$1 [QSA,L]

The parameters at the end:

  • [QSA] appends the query string (up to you);
  • [L] makes it the last rule

NB /redmine will not be matched by this rule, but I am going off what you tried, only subpaths, e.g. /redmine/abc

0

精彩评论

暂无评论...
验证码 换一张
取 消