Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewriting a Subdomain with mod-rewrite

I have a project that uses the moodle library. I had to change the URL from moodle.example.com to learn.example.com, due to a client request.

I thought this would be an easy change, but alas moodle inserts all links and images in with the complete url instead of the relative url.

Is it possible using mod-rewrite to point all requests to moodle.example.com to learn.example.com and maintain the query string?

Example:

I want a request to: http://moodle.example.com/course/view.php?id=2&topic=1 to go to http://learn.example.com/course/view.php?id=2&topic=1.

Is this possible?

Thanks,

Josh

like image 395
Josh Scott Avatar asked Apr 27 '10 17:04

Josh Scott


1 Answers

Try this rule:

RewriteCond %{HTTP_HOST} =moodle.example.com [NC]
RewriteRule ^ http://learn.example.com%{REQUEST_URI} [L,R=301]
like image 181
Gumbo Avatar answered Oct 18 '22 04:10

Gumbo