1

I would like that my website to be able to use vanity URLs.

There are 3 diffent types:

1) username - http://www.example.com/username --- it works fine

2) ignore php -extensionless url - it always works fine

3) vanity url

3) postal code and username - http://www.example.com/12345/username I find lot of examples for the first and second example, but not for the third example How can I solve this?

Please help. Thanks in advance!

RewriteEngine on
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.example.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://www.example.com/users.php?u=$1 [NC]
speakr
  • 4,141
  • 1
  • 22
  • 28
  • Can you list all URLs you want to support? I can't make heads or tails of these rewrite rules. Are you still trying to support `.php` URLs? – Halcyon Apr 25 '14 at 14:13
  • www.mysite.com/contact -> www.mysite.com/contact.php www.mysite.com/username -> www.mysite.com/users.php?u=username www.mysite.com/1234/username -> www.mysite.com/users.php?u=username&postal=1234 – user3573190 Apr 25 '14 at 21:34

0 Answers0