Syn Syn - 1 year ago 74
Apache Configuration Question

How do you ignore parts of a URL with Mod Rewrite?

I am using

Mod Rewrite
to create attractive URLs. I am trying to understand how it is possible to ignore parts of a URL?

For example, my original URL was:

And I have written a Mod Rewrite code to turn that into:

RewriteEngine On
RewriteRule ^file/([^/]*)$ /file.php?token=$1 [L]

However, I would like to achieve a URL like:

The random bits on the end serve no purpose (other than decoration). How do I tell Mod Rewrite to ignore this part of the URL?

Answer Source

Just tweak your regex like this

RewriteRule ^file/([^/]+)/?(.*)$ /file.php?token=$1 [NC,L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download