funerr
funerr

Reputation: 8156

.htaccess Mod_rewrite - I am confused

I am having trouble to get the following working:
I have my base domain: www.mydomain.com
And I want to redirect users via an .htaccess file like so:
If someone types:

www.mydomain.com/id


Then it will redirect to:

www.mydomain.com/directory/process?id=id



This is what I tried:

RewriteEngine On
RewriteRule ^v/([^/]*)$ /directory/process?id=$1 [L]

I've put it in the root directory (aka mydomain.com/)
Thanks in advance.

Upvotes: 1

Views: 53

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270637

To rewrite /id to /directory/process?id=xxx, capture everything before the first / if the request is not for a real existing file.

RewriteEngine On
# Don't rewrite if the request is for a real file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# ([^/]+) captures everything up to the first / in $1
RewriteRule ^([^/]+) directory/process?id=$1 [L]

Upvotes: 1

Related Questions