views:

22

answers:

1

Hey guys,

I'm currently rewriting urls from

http://domain.com/profile/?u=10000017564881

this to this

http://domain.com/profile/10000017564881

with the following rewrite

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)\/?$ index.php?u=$1 [L]

However I'd like to optimize for seo a litte and go with :

http://domain.com/profile/10000017564881/Anything-I-want-here

Obviously the /Anything-I-want-here is just null ignored ...

Any idea's guys? much appreciated

+3  A: 

Simply remove the $ from the regex, and anything after the ID number will be ignored, and the URL will be rewritten correctly.

RewriteRule ^(.*?)\/? index.php?u=$1 [L]

# the following will work the same (as far as I can tell), and
# it's a lot more obvious at first glance what it does, which is
# match everything until the first slash
RewriteRule ^([^/]+)     ...

When I do something like this, I like to verify the URL in code, and 301 redirect if the "Anything-I-want-here" doesn't match the data.

zildjohn01
RewriteRule ^([^/])\/? index.php?u=$1 [L] Like this? doesn't seem to work buddy Did I write it correctly?
Webby
You're right, I forgot a `+`. I tested the updated one at http://regexpal.com/ and it works fine. You can omit the `\/?` and it will still work.
zildjohn01
Awesome buddy thank you! +1
Webby
Glad to help --
zildjohn01