I have several .htaccess rules I would like to combine. Here's the gist of what I want to accomplish:
jethro.mysite.com -> Redirects to -> gallery.mysite.com/?username=jethro&page_name=Home (note: page_name is = Home if not already specified)
jethro.mysite.com/ajax/dir/script.php -> Redirects to -> gallery.mysite.com/ajax/dir/script.php
Anything else is processed like normal. Example: jethro.mysite.com/includes/blah.css -> Redirects to -> gallery.mysite.com/includes/blah.css
So far my .htaccess located at jethro.mysite.com looks like this, but I get an infinite loop:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^jethro.mysite.com [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule (.*) http://jethro.mysite.com/?username=jethro&page_name=Home [P]
RewriteCond %{QUERY_STRING} page_name=script
RewriteRule (.*) http://gallery.mysite.com/ajax/dir/script\.php [P]
RewriteCond %{QUERY_STRING} page_name=(.*)
RewriteRule (.*) http://gallery.mysite.com/?username=jethro&page_name=%1 [P]
If I disable the 5th and 6th lines above it will no longer do the loop. Please help how do I combine these ideas? Thanks!
Try the following.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^jethro.mysite.com [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule . http://jethro.mysite.com/?username=jethro&page_name=Home [P,L]
RewriteCond %{QUERY_STRING} page_name=script [NC]
RewriteRule . http://gallery.mysite.com/ajax/dir/script\.php [P,L]
RewriteCond %{QUERY_STRING} page_name=(.*) [NC]
RewriteCond %1 !=script [NC]
RewriteRule . http://gallery.mysite.com/?username=jethro&page_name=%1 [P,L]
I also assume that the [p] is intentional ie you want to proxy the request.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.