Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Wed Nov 14, 2012 1:33 am 
Offline
Junior Member

Joined: Wed Mar 17, 2010 3:24 pm
Posts: 26
I’d like: http://www.example.com/username

to redirect to: http://www.example.com/user.php?id=username

Trying to use this mod_rewrite rule I found: RewriteRule ^user/(\w+)/?$ user.php?id=$1

However, I have something wrong. It doesn’t work (shocker!). I’ve tried a lot of different things, but no luck. Any advice linode ninjas? Thank you!

<VirtualHost xxx.xxx.xxx.xxx.:443>
ServerAdmin webmaster@localhost
ServerName example.com
ServerAlias http://www.example.com

DocumentRoot /home/public

<Directory /home/public>
Options -Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

RewriteEngine On
RewriteRule ^user/(\w+)/?$ user.php?id=$1

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>

</VirtualHost>

_________________
I'm completely new to the LAMP stack.


Top
   
PostPosted: Wed Nov 14, 2012 11:03 am 
Offline
Senior Member

Joined: Sun May 23, 2010 1:57 pm
Posts: 315
Website: http://www.jebblue.net
You could instead use mod_proxy and in the VirtualHost section add these two lines:

ProxyPass /
ProxyPassREverse /user.php

Then update user.php to look at the url and parse the username.

For any directories that should not be part of username processing like:

http://www.example.com/foo

You could tell Apache to pass those urls through as is with:

ProxyPass /foo !


Top
   
PostPosted: Thu Nov 15, 2012 5:39 pm 
Offline
Junior Member

Joined: Wed Mar 17, 2010 3:24 pm
Posts: 26
I'll have a look at this mod_proxy and give it a try - thanks!

_________________
I'm completely new to the LAMP stack.


Top
   
PostPosted: Thu Nov 15, 2012 6:45 pm 
Offline
Junior Member

Joined: Sun Jun 24, 2012 4:27 pm
Posts: 29
eekeek wrote:
Trying to use this mod_rewrite rule I found: RewriteRule ^user/(\w+)/?$ user.php?id=$1

Your RewriteRule here expects a url that looks like: http://www.example.com/user/username, which will redirect to http://www.example.com/user.php?id=username.

If you really want to use http://www.example.com/username, then you are going to have some added complication. What if i register my username as index.php?


Top
   
PostPosted: Thu Nov 15, 2012 8:12 pm 
Offline
Junior Member

Joined: Sun May 06, 2012 2:30 pm
Posts: 25
Location: San Diego, California
bacon wrote:
eekeek wrote:
Trying to use this mod_rewrite rule I found: RewriteRule ^user/(\w+)/?$ user.php?id=$1

Your RewriteRule here expects a url that looks like: http://www.example.com/user/username, which will redirect to http://www.example.com/user.php?id=username.

If you really want to use http://www.example.com/username, then you are going to have some added complication. What if i register my username as index.php?


You're right about the incorrect rule, and I don't use Apache but I remember you could have rewrite conditions to make sure a file does NOT exist before rewriting. In that case it would just serve index.php instead of redirecting, so the user loses that functionality. To prevent this, you could just disallow dots in usernames.

Also I'd recommend a rewrite for this purpose instead of a reverse proxy.


Top
   
PostPosted: Sun Nov 18, 2012 1:57 pm 
Offline
Junior Member

Joined: Sun Jun 24, 2012 4:27 pm
Posts: 29
jerzzp wrote:

You're right about the incorrect rule, and I don't use Apache but I remember you could have rewrite conditions to make sure a file does NOT exist before rewriting. In that case it would just serve index.php instead of redirecting, so the user loses that functionality. To prevent this, you could just disallow dots in usernames.


Don't rewrite if it matches a directory:
RewriteCond %{SCRIPT_FILENAME} -d

Or file:
RewriteCond %{SCRIPT_FILENAME} -f


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group