Syn Syn - 1 month ago 11
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:
/file.php?token=771736eb78bc3b6f96d5c066069567c0c219bf65/


And I have written a Mod Rewrite code to turn that into:
/file/771736eb78bc3b6f96d5c066069567c0c219bf65/


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


However, I would like to achieve a URL like:
/file/771736eb78bc3b6f96d5c066069567c0c219bf65/random-bits-here/


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

Just tweak your regex like this

RewriteRule ^file/([^/]+)/?(.*)$ /file.php?token=$1 [NC,L]