1

I am developing a short link website for a brand, and I need to have the links look like this:

http://demo-name.com/[shortvalue]

I understand how to do this as following:

http://demo-name.com/l/[shortvalue]

using a basic rewrite rule, however, I am unsure of how to do this without the prefix of the l.

I will also need to be able to go to

http://demo-name.com/file.php

to run certain files, so this needs to be possible.

If it is also possible, I would like to be able to have a

http://demo-name.com/[shortvalue]?key=val&key2=val2
                                 ^^^^^^^^^^^^^^^^^^

query string at the end of my URL's, so if [QSA] is possible as well, that would be great!

1 Answer 1

2

You can test if a file is a directory (-d) or a file (-f) in a RewriteCond.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/\.]+)$ index.php?shorturl=$1 [L,QSA]

This rule will rewrite any "shortvalue" without slashes or dots to index.php?shorturl=shortvalue.

Not the answer you're looking for? Browse other questions tagged or ask your own question.