Forum Moderators: phranque

Message Too Old, No Replies

Whats wrong with this code?

         

nfs2

1:52 am on Feb 24, 2006 (gmt 0)

10+ Year Member



I have a journal at mydomain.com/journal?user=me

and i want mydomain.com/me

here is the code im trying to use

RewriteRule ^/([0-9]*) journal?user=$1 [L]

I need to have the username as a wildcard.

I get a not found error when i try to use it. Can anyone help?

jdMorgan

1:59 am on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) Where is this code installed?
2) Your code only works with numeric "usernames" - others will be dropped.

Jim

nfs2

2:01 am on Feb 24, 2006 (gmt 0)

10+ Year Member



Its in my .htaccess file with some other stuff

Heres the whole file in case something else could affact it

RewriteEngine on

RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule (.*) [mysite.com...] [R=301,L]
<FilesMatch "^[^\.]+$">
ForceType application/x-httpd-php
</FilesMatch>

DirectoryIndex index.html.var index.htm index.html index.php index
php_value register_globals Off
php_value track_vars On
php_value arg_separator.output "&amp;"
php_value arg_separator.input "&"

jdMorgan

2:17 am on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your approach as apparently intended will leave no room to grow your site or to use any subdirectories. Unless you tell it othewise, mod_rewrite will rewrite *all* requests to /journal?user=username. And that includes images, css stylesheets, external javascripts, and even /journal?user=robots.txt!

Before setting out down this path, I suggest you consder adding a 'key' to the URL so that mod_rewrite can detect it. Otherwise, you may have to exclude a lot of files from being rewritten, and this list will grow over time.

For example, you could use URLs of the form

example.com/users/me

and then use the code:


RewriteRule ^users/([a-z_0-9]+)$ /journal?user=$1 [L]

The limitation of usernames to lowercase letters, underscore, or digits 0-9 only is intentional.

Alternatively, if your host allows wild-card subdomains and will deliver requests for them to your Web root folder, you could use URLs like:

me.example.com

and change the code to get the username from the subdomain (excluding www, of course).

Jim

nfs2

2:20 am on Feb 24, 2006 (gmt 0)

10+ Year Member



Thanks for your help! I've been trying to talk my host into configuring wildcard subdomains for a while now. They dont currently support it so i'll use this untill they do

Thanks again!