Rewrite Rule to Simplify Subdomain

I have a subdomain that works like this:

I want to have a rewriterule in my subdomain folder (“sub”) that allows this to work the same way:

I did a feeble attempt with this with no success:

RewriteRule ^/?([-0-9a-zA-Z#]+) index.php?v=$1

All feedback appreciated


That rule looks pretty much okay to me (altough the hash makes no sense, but okay).
You still need to take into account that it should only work on the subdomain, and that it should only fire if there is no real file or directory with the requested name.

All together that would be something like:

# Enable the RewriteEngine
RewriteEngine On
# If the request is for ...
RewriteCond %{HTTP_HOST} ^sub\\.example\\.com$
# ... and the requested filename is not a directory ...
RewriteCond %{REQUEST_FILENAME} !-d
# ... and the requested filename is not a file ...
RewriteCond %{REQUEST_FILENAME} !-f
# ... Redirect it to index.php
RewriteRule ^/?([-0-9a-zA-Z]+) index.php?v=$1

If you are on apache1.x change ^/? at the start of the rule to ^/
If you are on apache2.x change ^/? at the start of the rule just ^

Thanks, it worked!

I didn’t change the rewriterule at all.

Should I?


If this v parameter can contain other things that digits or characters you should change it. If not, it’s fine as it is :slight_smile:

This sort of brings me to another issue. Not wanting to go too far away from original topic, but I’m thinking about installing litespeed over apache and I was wondering how that would effect all my rewriterules.

foresee a problem?



Litespeed is supposed to mimic Apache - at least in the mod_rewrite area. Give it a try (on a test computer) and see.