LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-15-2013, 08:05 AM   #1
compused
Member
 
Registered: Oct 2006
Location: Melbourne Australia
Distribution: centos and redhat 8
Posts: 83

Rep: Reputation: 15
.htaccess and redirect - not making sense


Hi
I have these two virtualhost entries in httpd.conf; here is the first:
Code:
NameVirtualHost *:80
#
<VirtualHost *:80>
DocumentRoot "/home/main_directory/drupal"
ServerName hol-server.com.au
<Directory "/home/main_directory/drupal">
   	Order                          Allow,Deny
  	Allow                          From All
	Options FollowSymlinks +Indexes
	AllowOverride All
</Directory>
</VirtualHost>
here is the second, which has nothing to do with drupal - the problem is that the rewrite rule is ignored (see the # lines):
Code:
<VirtualHost *:80>
DocumentRoot /var/www/html/cpserver
ServerName www.cpserver.org.au
<Directory "/var/www/html/cpserver">
AllowOverride none
Order Allow,Deny
Allow from all
Options FollowSymlinks +Indexes
<IfModule mod_rewrite.c>
 RewriteEngine on
 #RewriteBase /var/www/html/ # did not help
 #the expected rewrite is not happening
 RewriteCond %{HTTP_HOST} ^cpserver\.org\.au$ [NC]
 RewriteRule ^(.*)$ http://www.cpserver.org.au/$1 [L,R=301]
</IfModule>
</Directory>
</VirtualHost>
in /home/main_directory/drupal/.htaccess I have:
Code:
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^hol-server\.com\.au$ [NC]
  RewriteRule ^(.*)$ http://www.hol-server.com.au/$1 [L,R=301]
# uncommenting the line below enables the rewrite, but it should not as cpserver is  under a completely different directory
#  RewriteCond %{HTTP_HOST} ^cpserver\.org\.au$ [NC]
#  RewriteRule ^(.*)$ http://www.cpserver.org.au/$1 [L,R=301]
</IfModule>
the other anomaly is that moving the www.cpserver.org.au virtualhost to above the hol-server.com.au entry in httpd.conf, enables the rewrite but then hol-server.com.au redirects to cpserver.org.au

apache is restarted after each change, though changes in .htaccess do not seem to need a restart.

Any help would be good - have been working on this for a few nights now.
Compfused
 
Old 02-15-2013, 08:22 AM   #2
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 51
Are you using apache2 for web development environment?
I mean, you are not using XAMPP. correct?

1) Can you check following line in your /etc/apache2/apache2.conf
Code:
AddHandler application/x-httpd-php .htm
If it is not there then add it, Now restart apache and try.

2) Check following line in your apache conf file
Code:
AccessFileName .htaccess
3) Add following lines in your httpd.conf file
Code:
<Directory /your/drupal/project/path>
    AddHandler cgi-script .cgi
    Options +Indexes +ExecCGI
    AllowOverride all
    </Directory>
Restart Apache.

Last edited by fortran; 02-15-2013 at 08:37 AM.
 
1 members found this post helpful.
Old 02-15-2013, 09:03 AM   #3
compused
Member
 
Registered: Oct 2006
Location: Melbourne Australia
Distribution: centos and redhat 8
Posts: 83

Original Poster
Rep: Reputation: 15
thanks ++ PK - the AddHandler directive worked a treat!
So simple!
Compfused
 
Old 02-16-2013, 09:13 AM   #4
compused
Member
 
Registered: Oct 2006
Location: Melbourne Australia
Distribution: centos and redhat 8
Posts: 83

Original Poster
Rep: Reputation: 15
An update on this...its an apache2 linux server, and the expected rewrite is not happening after I moved another drupal based virtualhost, call it drupal2, to the new location of /var/www/html:

ie we have
hol-server.com.au with DirectoryRoot of /home/main_directory/drupal
and
drup2-server.com.au with DirectoryRoot of /var/www/html/drupal2, but originally /home/main_directory/drupal2

For rewriting purposes, even after the move to the completely different directory, I can't seem to free drup2-server.com.au from its dependency on the original /home/main_directory/drupal/.htaccess file. The moved site is otherwise working normally


drup2-server.com.au 's httpd.conf entry is now:
Code:
<VirtualHost *:80>
DocumentRoot "/var/www/html/drupal2"
ServerName drup2-server.com.au
<Directory "/var/www/html/drupal2">
   	Order                          Allow,Deny
  	Allow                          From All
	Options FollowSymlinks +Indexes
	AllowOverride All  <---'All' is needed otherwise drupal2 doesn't work
<IfModule mod_rewrite.c>
 RewriteEngine on
 #RewriteBase /var/www/html/ <-- this did not help
 #the expected rewrite is not happening:
 # instead of the rewrite I get 'hol-server.com.au' when typing 'drup2-server.com.au', 
 # using the 'www' prefix shows the drup2-server.com.au normally
 # the only way to rewrite the www is via an entry in /home/main_directory/drupal/.htaccess
 RewriteCond %{HTTP_HOST} ^drup2-server\.com\.au$ [NC]
 RewriteRule ^(.*)$ http://www.drup2-server.com.au/$1 [L,R=301]
</IfModule>
</Directory>
</VirtualHost>
Also in httpd.conf as advised above I have:
Code:
AccessFileName .htaccess
AddHandler application/x-httpd-php .htm

I also tried putting the rewrite directives into /var/www/html/drupal2/.htaccess, but that did not help either. Apache was restarted.
Any idea on this one please?
Thanks
Compused
Edit: have removed the [SOLVED] label due to this subsequent unexpected finding.

Last edited by compused; 02-16-2013 at 06:33 PM.
 
Old 02-18-2013, 12:30 AM   #5
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 51
Add following lines in your httpd.conf file
Code:
<Directory /your/drupal/project/path>
    AddHandler cgi-script .cgi
    Options +Indexes +ExecCGI
    AllowOverride all
    </Directory>
Restart Apache.
 
Old 02-18-2013, 02:03 AM   #6
d3vrandom
Member
 
Registered: Jun 2006
Location: Karachi, Pakistan
Distribution: OpenSUSE, CentOS, Debian
Posts: 59

Rep: Reputation: 9
The problem is simple. You need to use serveralias if you want multiple names pointing to the same virtual host. So in the case of the first virtual host you need to add the www as the server alias:

Code:
servername hol-server.com.au
Serveralias www.hol-server.com.au  #add this
And in the case of the second one the non-www version:

Code:
Servername www.cpserver.org.au
Serveralias cpserver.org.au #add this
 
Old 02-18-2013, 08:35 AM   #7
compused
Member
 
Registered: Oct 2006
Location: Melbourne Australia
Distribution: centos and redhat 8
Posts: 83

Original Poster
Rep: Reputation: 15
Thanks, both of you guys. I'm crying. Its working. Fantastic relief.
Think it was the serveralias that did the trick.
Compfused
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to redirect to three different domains with .htaccess? plotinus Linux - Server 2 11-24-2011 01:38 AM
Redirect with htaccess chandranjoy Linux - Server 1 02-16-2011 08:40 AM
Apache htaccess redirect Jorkim Kustafin Linux - Server 2 07-23-2009 01:32 PM
making sense of sync() kornelix Programming 1 01-18-2008 11:49 AM
Htaccess with a redirect Diode Linux - Networking 0 10-28-2003 07:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration