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.

asked Dec 2, 2013 at 17:22

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.

answered Dec 2, 2013 at 17:27
Sign up to request clarification or add additional context in comments.

6 Comments

I'd like to redirect applications that are in directories below the /apps/dept/ directory.
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.
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.
It works for the /apps/dept/ directory but not for the apps in the subdirectories.
You are correct. This solution works and this issue is resolved. Thanks.
|
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]
answered Dec 2, 2013 at 17:25

1 Comment

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?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.