DANGER! simple mod_rewrite question... o_O
to redirect to:
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!
ServerName example.com
ServerAlias
DocumentRoot /home/public
AllowOverride None
Order allow,deny
allow from all
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
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
5 Replies
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:
You could tell Apache to pass those urls through as is with:
ProxyPass /foo !
@eekeek:
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 tohttp://www.example.com/user.php?id=username .
If you really want to use
@bacon:
@eekeek: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 tohttp://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.
@jerzzp:
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