3

We are changing our domain name and this is meant to work for stand alone applications. In Apache virtual host file the DocumentRoot is /var/www/website/html, not /var/www/example/html as in this block:

Alias /apps/dept /var/www/example/html/apps/dept
<Directory "/var/www/example/html/apps/dept/">
   Options FollowSymLinks
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>

I put an .htaccess file in /var/www/example/html/apps/dept directory as follows:

 RewriteEngine On
 RewriteBase /apps/dept/
 RewriteCond %{HTTP_HOST} ^example.orgname.state.tx.us/apps/dept [NC]
 RewriteRule ^(.*)$ http://example.orgname.texas.gov/apps/dept/$1 [L,R=301]

This seems to follow what is recommended here, http://httpd.apache.org/docs/current/mod/mod_rewrite.html and Apache : How to Use Rewrite Engine Inside Alias. I see no results. The new domain has a virutal host config in the VH file, also. This same basic rewrite works for our Drupal website which does not use an alias. What changes might be necessary to have the domain name rewritten with an appended application pathname? Is the RewriteBase incorrect?

Thx.

2 Answers 2

3

So you only want to redirect /apps/dept/, correct? This should work. Place it as an .htaccess or in the Apache config for example.orgname.state.tx.us and all should work as expected.

RewriteEngine on
RewriteRule ^/apps/dept/(.*)$ http://example.orgname.texas.gov/apps/dept/$1 [NC,L,R=301]

So now, any requests going to this URL

http://example.orgname.state.tx.us/apps/dept/

Will now go to this URL:

http://example.orgname.texas.gov/apps/dept/

And any request parameters to the right of the URL will be passed along as well.

EDIT Just reread what you wrote here:

I put an .htaccess file in /var/www/example/html/apps/dept directory as follows.

The .htaccess I described above should be placed in /var/www/example/html/ and not in the /apps/dept subdirectory.

But if you want the same behavior from an .htaccess placed in /apps/dept then use this:

RewriteEngine on
RewriteRule ^(.*)$ http://example.orgname.texas.gov/apps/dept/$1 [NC,L,R=301]

This way any request made from /apps/dept will to to example.orgname.texas.gov/apps/dept/ including subdirectories of /apps/dept such as /apps/dept/test_app1, /apps/dept/test_app2 or /apps/dept/test_app3.

Or perhaps try this:

RewriteEngine on
RewriteRule (.*)$ http://example.orgname.texas.gov/apps/dept/$1 [NC,L,R=301]

Note I removed the ^ which would force the RewriteRule to match the beginning of the URL.

6
  • I'd like to redirect applications that are in directories below the /apps/dept/ directory.
    – edroms
    Commented Dec 2, 2013 at 17:49
  • Hope to include these directories: example.on.state.tx.us/apps/dept/myapp to example.on.texas.gov/apps/dept/myapp. There are about 10 applications in the dept dir.
    – edroms
    Commented Dec 2, 2013 at 18:22
  • Thanks. I tried a copy/paste of the above .htaccess contents in the /apps/dept/ dir and this returned example.on.texas.gov/var/www/example/html/apps/dept/… in the URL box of the browser. Looks like the reverse alias is in it. So close.
    – edroms
    Commented Dec 2, 2013 at 19:05
  • It works for the /apps/dept/ directory but not for the apps in the subdirectories.
    – edroms
    Commented Dec 2, 2013 at 20:04
  • 1
    You are correct. This solution works and this issue is resolved. Thanks.
    – edroms
    Commented Dec 2, 2013 at 20:50
0

You cannot match Request URI in %{HTTP_HOST} variable, it matches only domain name. Chang your rule to:

 RewriteEngine On
 RewriteBase /apps/dept/

 RewriteCond %{HTTP_HOST} ^example\.orgname\.state\.tx\.us$ [NC]
 RewriteRule ^(.*)$ http://example.orgname.texas.gov/apps/dept/$1 [L,R=301]
1
  • This works for the /apps/dept/ directory only, but not for directories under dept. Is there a way to take care of all the app dirs under the dept without doing and .htaccess for each application?
    – edroms
    Commented Dec 2, 2013 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.