LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-04-2016, 06:28 PM   #1
deathsfriend99
Member
 
Registered: Nov 2007
Distribution: CentOS 6
Posts: 200

Rep: Reputation: 22
Apache Rewrite Userdir's


So this is kind of complicated. I have a CentOS6 box with apache. We recently changed domain names, but want to keep the old domain for legacy purposes.
www.olddomain.company.com > www.newdomain.company.com

I use mod_userdir so users have their own public_html space.
I want www.olddomain.company.com/~username to go to www.newdomain.company.com/~username

Here's where it gets a bit tricky. www.olddomain.company.com still exists as a virtuahost on the same server. I want those to stay where they are. I just want to rewrite the /~usernames.

I've tried different permutations of RewriteCond and RewriteRule with no luck.

Any suggestions?
 
Old 04-05-2016, 02:05 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,168
Blog Entries: 1

Rep: Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038
Hi,

Quote:
I want www.olddomain.company.com/~username to go to www.newdomain.company.com/~username

Here's where it gets a bit tricky. www.olddomain.company.com still exists as a virtuahost on the same server. I want those to stay where they are. I just want to rewrite the /~usernames.
So you want to rewrite only the request for userdirs to the new domain.
If that's the case, you can use the following:
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.olddomain.company.com
RewriteCond %{REQUEST_URI} ^/~(.+)
RewriteRule (.*) http://www.newdomain.company.com/~%1[L,R=301]
Regards
 
Old 04-05-2016, 08:50 AM   #3
deathsfriend99
Member
 
Registered: Nov 2007
Distribution: CentOS 6
Posts: 200

Original Poster
Rep: Reputation: 22
Thanks. Perhaps I'm doing something wrong. I can't get mod_rewrite to work at all.

It is loaded
Code:
LoadModule rewrite_module modules/mod_rewrite.so
Here are the relevant lines of my httpd.conf

Code:
<VirtualHost 999.999.999.999:80>
ServerName www.newdomain.company.com:80
ServerAlias www.newdomain.company.com:80
DirectoryIndex index.html index.htm index.cgi index.pl index.php index.xhtml 
DocumentRoot "/www/html"

<Directory "/www/html">
Options +Includes ExecCGI +FollowSymLinks +Indexes 
    AllowOverride None
    Order allow,deny
    Allow from all

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^www.olddomain.company.com
RewriteCond %{REQUEST_URI} ^/~(.+)
RewriteRule (.*) http://www.newdomain.company.com/~%1[L,R=301]

</Directory>

What could I be doing wrong here?
 
Old 04-05-2016, 03:29 PM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,168
Blog Entries: 1

Rep: Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038
Hi

Quote:
Perhaps I'm doing something wrong. I can't get mod_rewrite to work at all.
You should put the rewrite stuff inside:
Code:
<Directory /home/*/public_html>
...
</Directory
 
Old 04-06-2016, 09:10 AM   #5
deathsfriend99
Member
 
Registered: Nov 2007
Distribution: CentOS 6
Posts: 200

Original Poster
Rep: Reputation: 22
I'm using mod_userdir for user directories. They are nfs mounted.
Code:
<IfModule mod_userdir.c>
    
    UserDir public_html
    
</IfModule>
So I don't have a <Directory> listing for these.
 
Old 04-06-2016, 11:00 AM   #6
deathsfriend99
Member
 
Registered: Nov 2007
Distribution: CentOS 6
Posts: 200

Original Poster
Rep: Reputation: 22
Ok, Finally got it. Thanks for pointing me in the right direction.

I was putting the rewrite in the <virtualhost> of the newdomain.company.com
It needs to be in the olddomain.company.com's virtualhost section.
That makes sense, but I just didn't think of it.

Code:
<VirtualHost 999.999.999.999:80>
    ServerAdmin webmaster@olddomain.company.com
    DocumentRoot /www/html/oldcompany
    ServerName olddomain.company.com
    ServerAlias www.olddomain.company.com
    ErrorLog logs/olddomain

<Directory /www/html/oldcompany>
	AllowOverride All
	Options ExecCGI Includes FollowSymlinks +Indexes
	Order allow,deny
	Allow from all
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^www.olddomain.company.com
RewriteCond %{REQUEST_URI} ^/~(.+)
RewriteRule (.*) http://newdomain.company.com/~%1 [L,R=301]

</Directory>
 
  


Reply



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
Apache UserDir ]SK[ Linux - Software 4 06-18-2005 12:10 PM
Apache userdir. collen Linux - Networking 1 01-28-2005 12:24 PM
Apache UserDir Abbaddon Slackware 12 09-15-2004 11:28 AM
properly using Userdir apache 2.0 spoody_goon Linux - Networking 0 05-11-2004 09:29 AM
UserDir question apache Cigar Linux - Networking 10 02-10-2004 01:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:07 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