subdomain to different url without changing browser

Using a single web hosting account to host multiple sites

Postby richardk » Mon Dec 15, 2008 8:38 am

Removing the leading /'s from the main redirect allowed the site to work

From where. Please be specific.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jwilson » Mon Dec 15, 2008 8:40 am

I changed:

RewriteRule ^(/.*)$ /index.php$1 [L]

To:

RewriteRule ^(.*)$ index.php$1 [L]

And the front page no longer 404ed, but none of the links worked. Just "BAD REQUEST" as the response.
jwilson
 
Posts: 10
Joined: Wed Dec 10, 2008 9:12 am

Postby richardk » Mon Dec 15, 2008 9:22 am

Does the /trouvez/ redirect work with any of the versions (if it does please be specific about which one)?

Try
Code: Select all
<VirtualHost 192.168.1.1>
  Servername www.domain.com
  ServerAlias  *.domain.com
  DocumentRoot /virtual/domain

  ErrorLog /var/log/httpd/error.log
  CustomLog /var/log/httpd/access.log combined
  ErrorDocument 500 /500.html
  ErrorDocument 404 /404.html
  LogLevel warn

  Alias /content /virtual/images
  Alias /georef /virtual/georef

  <Directory "/virtual/domain">
    Options +FollowSymLinks
    AllowOverride None
  </Directory>

  # Compress all data out, except images
  <Location />
    SetOutputFilter DEFLATE
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    Header append Vary User-Agent env=!dont-vary
  </Location>

  RewriteEngine On

  # Captures wierd legacy domain names
  RewriteCond %{HTTP_HOST} ^www\.
  RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
  RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

  # Legacy company access
  RewriteCond %{HTTP_HOST} !^(www|m[0-9]+|us)\.domain\.com$ [NC]
  RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
  RewriteRule ^(.*)$ http://www.domain.com/companies/$1 [R=301,L]

  # Prefer www.domain.com to domain.com
  RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
  RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

  # Redirect for US site
  RewriteCond %{HTTP_HOST} ^us\.domain\.com$ [NC]
  RewriteRule ^$ /index.php/us [QSA,L]

  # Needed for embeddings
  RewriteRule ^(.+)\.iframe$ http://www.domain.com/embed/$1 [L]

  # Route french searches to the french site
  RewriteRule ^trouvez/(.*)$ http://www.domain.com/fr/trouvez/$1 [R=301,L]

  # Redirect /fr/find/ to /fr/trouvez
  RewriteRule ^fr/find/(.*)$ http://www.domain.com/fr/trouvez/$1 [R=301,L]

  # Redirect /find/XXXXXX/ to /find/XXXXXX
  RewriteRule ^find/(.*)/$ http://www.domain.com/find/$1 [R=301,L]

  # Redirect http://www.domain.com/fr to http://www.domain.com/fr/
  RewriteRule ^fr$ http://www.domain.com/fr/ [R=301,L]

  # Redirct http://www.domain.com/?source=olddomain to http://www.domain.com/
  RewriteCond %{QUERY_STRING} ^(.*&)?source=olddomain(&.*)?$ [NC]
  RewriteRule ^$ http://www.domain.com/ [R=301,L]

  # Redirect http://www.domain.com/?lang=fr and http://www.domain.com/?language=fr to http://www.domain.com/fr/
  # Redirect http://www.domain.com/index.php?lang=fr and http://www.domain.com/index.php?language=fr to http://www.domain.com/fr/
  RewriteCond %{QUERY_STRING} ^(.*&)?lang(uage)?=fr(&.*)?$ [NC]
  RewriteRule ^(index\.php)?$ http://www.domain.com/fr/ [R=301,L]

  # Redirect http://www.domain.com/index.php?lang=en and http://www.domain.com/index.php?language=en to http://www.domain.com/
  RewriteCond %{QUERY_STRING} ^(.*&)?lang(uage)?=en(&.*)?$ [NC]
  RewriteRule ^index\.php$ http://www.domain.com/ [R=301,L]

  # Checks to see if the user is attempting to access a valid file,
  # such as an image or css document, if this isn't true it sends the
  # request to index.php
  RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f
  RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-d
  RewriteRule ^(.*)$ /index.php/$1 [L]
</VirtualHost>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jwilson » Mon Dec 15, 2008 9:33 am

I just tested it and it looks like the trouvez does not actually rewrite to the new URL. With the old config.

I tried the new config with the same results as the old one. Removing the leading slash from index.php on the last one makes it work but then all the links fail.
jwilson
 
Posts: 10
Joined: Wed Dec 10, 2008 9:12 am

Postby richardk » Mon Dec 15, 2008 9:42 am

Try, does the "/trouvez/a" redircet work?
Code: Select all
<VirtualHost 192.168.1.1>
  Servername www.domain.com
  ServerAlias  *.domain.com
  DocumentRoot /virtual/domain

  ErrorLog /var/log/httpd/error.log
  CustomLog /var/log/httpd/access.log combined
  ErrorDocument 500 /500.html
  ErrorDocument 404 /404.html
  LogLevel warn

  Alias /content /virtual/images
  Alias /georef /virtual/georef

  <Directory "/virtual/domain">
    Options +FollowSymLinks
    AllowOverride None

    RewriteEngine On

    # Captures wierd legacy domain names
    RewriteCond %{HTTP_HOST} ^www\.
    RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

    # Legacy company access
    RewriteCond %{HTTP_HOST} !^(www|m[0-9]+|us)\.domain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/companies/$1 [R=301,L]

    # Prefer www.domain.com to domain.com
    RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

    # Redirect for US site
    RewriteCond %{HTTP_HOST} ^us\.domain\.com$ [NC]
    RewriteRule ^$ /index.php/us [QSA,L]

    # Needed for embeddings
    RewriteRule ^(.+)\.iframe$ http://www.domain.com/embed/$1 [L]

    # Route french searches to the french site
    RewriteRule ^trouvez/(.*)$ http://www.domain.com/fr/trouvez/$1 [R=301,L]

    # Redirect /fr/find/ to /fr/trouvez
    RewriteRule ^fr/find/(.*)$ http://www.domain.com/fr/trouvez/$1 [R=301,L]

    # Redirect /find/XXXXXX/ to /find/XXXXXX
    RewriteRule ^find/(.*)/$ http://www.domain.com/find/$1 [R=301,L]

    # Redirect http://www.domain.com/fr to http://www.domain.com/fr/
    RewriteRule ^fr$ http://www.domain.com/fr/ [R=301,L]

    # Redirct http://www.domain.com/?source=olddomain to http://www.domain.com/
    RewriteCond %{QUERY_STRING} ^(.*&)?source=olddomain(&.*)?$ [NC]
    RewriteRule ^$ http://www.domain.com/ [R=301,L]

    # Redirect http://www.domain.com/?lang=fr and http://www.domain.com/?language=fr to http://www.domain.com/fr/
    # Redirect http://www.domain.com/index.php?lang=fr and http://www.domain.com/index.php?language=fr to http://www.domain.com/fr/
    RewriteCond %{QUERY_STRING} ^(.*&)?lang(uage)?=fr(&.*)?$ [NC]
    RewriteRule ^(index\.php)?$ http://www.domain.com/fr/ [R=301,L]

    # Redirect http://www.domain.com/index.php?lang=en and http://www.domain.com/index.php?language=en to http://www.domain.com/
    RewriteCond %{QUERY_STRING} ^(.*&)?lang(uage)?=en(&.*)?$ [NC]
    RewriteRule ^index\.php$ http://www.domain.com/ [R=301,L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to index.php
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
  </Directory>

  # Compress all data out, except images
  <Location />
    SetOutputFilter DEFLATE
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    Header append Vary User-Agent env=!dont-vary
  </Location>
</VirtualHost>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jwilson » Mon Dec 15, 2008 10:46 am

That one works! Thanks!

What was the difference beyond being inside the Directory statement?
jwilson
 
Posts: 10
Joined: Wed Dec 10, 2008 9:12 am

Postby richardk » Tue Dec 16, 2008 6:38 am

I'm not totally sure why that one works and my first attempt in the <VirtualHost> did not. In <VirtualHost>s you usually have to match the full path (ie. including the / at the beginning) and in <Directory>s and .htaccess files it is usually relative to the current directory. The last one is in a <Directory> matching relative paths.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Previous

Return to Domain Handling

Who is online

Users browsing this forum: Majestic-12 [Bot] and 27 guests

cron