Web Hosting Talk







View Full Version : Yet another URL redirect / mod rewrite question


Acroplex
10-09-2006, 12:03 AM
Alright, if anyone would give me a quick solution to this, I'd be greatful :)

I'd like to have this:

1. http://sampledomain.com/index.php?user=jim_doe

...display as this:

2. http://sampledomain.com/jim_doe

In other words when http://sampledomain.com/jim_doe is typed, the actual page pulled would be the first one, but the second URL will be displayed.

Any ideas?

astellar
10-09-2006, 05:34 AM
Try to put this in .htaccess:

RewriteEngine on
RewriteRule ^([^\/]+) /index.php?user=$1 [NC,L]

Rewrite rule description can be found here: http://look4docs.com/apache+rewriterule.shtml

But I suggest not to use http://sampledomain.com/jim_doe urls
just because of possible URL conflicts with http://sampledomain.com/index.php.
Use http://sampledomain.com/users/jim_doe instead.
Here is rewrite sample:

RewriteEngine on
RewriteRule ^/users/(.*) /index.php?user=$1 [NC,L]

Acroplex
10-09-2006, 10:13 AM
Thanks astellar. Why would there be a URL conflict, as long as there is filtration of characters, e.g. allowing only alphanumeric and converting spaces to underscores?

azizny
10-09-2006, 05:50 PM
I am trying to redirect from a subdomain to a page (opposite of above).

i tried to use:

RewriteCond %{HTTP_HOST} ([^.]+)\.site.com [NC]
RewriteRule ^(.*) http://www.site.com/page.php?name=%1 [P]

but would give me internal error..

Peace,