Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite: between two subdomains two sub folders

how to internaly redirect between subdomains

         

Nino_D

4:23 pm on Jan 31, 2008 (gmt 0)

10+ Year Member



I have another tricky problem: when asked for
[widgets.example.com...]
the goal is to serve content from
[gizmos.example.com...]
using mod_rewrite (internal redirection)

Server settings are:
<VirtualHost xyz.xy.xyz.xyz:80>
ServerAdmin webadm@example.com
DocumentRoot /var/www/htdocs/widgets.example.com
ServerName widgets.example.com
ErrorLog /var/log/httpd/widgets.example.com-error_log
CustomLog /var/log/httpd/widgets.example.com-access_log common
php_admin_flag safe_mode off
</VirtualHost>
<Directory "/var/www/htdocs/widgets.example.com">
Options +FollowSymLinks
AllowOverride All
RewriteEngine On
</Directory>
(and the same changing gismo for widgets for gismo.example.com)

I have tried using numerous rules in [widgets.example.com] .htacces

RewriteRule ^wsub/([0-9]+)-([0-9]+)-(.+)$ /gsub/index.php?category=$1&subcategory=$2 [NC,L]
OR
RewriteRule ^wsub/([0-9]+)-([0-9]+)-(.+)$ /var/www/htdocs/gizmo/gsub/index.php?category=$1&subcategory=$2 [NC,L]

but no result.

I guess full /var/www/htdocs/widgets.example.com creates problem, making impossible for rules in htaccess to jump from widgets.example.com to gizmo.example.com.

I haven't found any solution for this problem. Any ideas?

jdMorgan

4:52 am on Feb 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you got other working rules?

Have you tried something simple? If not, rename your current .htaccess file as a backup, and make a new one for testing with only this code in it:


Options +FollowSymLinks -MultiViews
RewriteEngine on
#
RewriteRule ^foo\.html$ http://www.webmasterworld.com/apache/ [R=301,L]

With that in place, a request to your server for /foo.html should land you back in this forum. :)

The path given for an internal rewrite should be relative to DocumentRoot. That is, the server will take care of prefixing DocumentRoot to the path you specify when mod_rewrite does the URL-to-filepath translation. You should not include the DocumentRoot path in your substitution URL-path.

Jim

Nino_D

1:15 pm on Feb 1, 2008 (gmt 0)

10+ Year Member



Have you got other working rules?
Yes, first check if computer is on : )
Other rules within same subdomain are working, no problem.
Also, external redirect (when including: http:// ) is working without problems.

My guess is when having
DocumentRoot /var/www/htdocs/widgets.example.com
and I try to internaly redirect to different subdomain using rule
RewriteRule ^wsub/([0-9]+)-([0-9]+)-(.+)$ /gsub/index.php?category=$1&subcategory=$2 [NC,L]
problem is that server is trying to locate:
/var/www/htdocs/widgets.example.com + /gsub/index.php?category=$1&subcategory=$2
instead
/var/www/htdocs/gadgets.example.com + /gsub/index.php?category=$1&subcategory=$2

How do I tell in .htaccess in just one specific RewrireRule "use different subdomain gadgets.example.com"
when settings for subdomain is:

<VirtualHost xyz.xy.xyz.xyz:80>
DocumentRoot /var/www/htdocs/widgets.example.com
ServerName widgets.example.com
</VirtualHost>
<Directory "/var/www/htdocs/widgets.example.com">
Options +FollowSymLinks
AllowOverride All
RewriteEngine On
</Directory>

Thanks.

jdMorgan

6:48 pm on Feb 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't tell mod_rewrite to use a different subdomain (unless you're externally redirecting to it) because subdomains are meaningless inside a server. You may have "subdirectories" or even different user-account filespaces, but to a server, everything is a file (or directory).

So, you can rewrite to a subdirectory in the current domain's filespace if you like, or rewrite to a 'fake' subdirectory that is 'mapped' into a different domain-account's filespace using a *nix symlink, but you can't 'change subdomains' using internal server functions.

To the outside world, you have domains and resource locators. Inside the server you have files. The main job of a server is to allow the OS- and server- neutral URL system to be used on the Web, and to translate that location system into the filesystem paths used by the operating system on a specific server.

HTH,
Jim