-3

I have this URL: http://www.my-domain.com/v/index.php?vid=euOUq6Sr-iujkdDzsw4s_uSX59Lhn2qqA=z15 I want to rewrite it to: http://v.my-domain.com/euOUq6Sr-iujkdDzsw4s_uSX59Lhn2qqA=z15

Note that: v -> which is folder name becomes at the beginning AND index.php?vid= -> hide

1 Answers1

0

Here's some new code based on the updated information. This worked in my testing environment.

    RewriteBase /v/
    RewriteCond %{HTTP_HOST} ^(www\.)?my-domain\.com$
    RewriteCond %{QUERY_STRING} ^vid=(.*)$
    RewriteRule ^(index.php)?$ http://v.my-domain.com/%1 [R=301,L]

There are still a few assumptions, so you may need to tweak it a bit if there are edge cases you didn't mention. For example, this snippet:

  1. Requires the query string to always be present
  2. Expects no other query variable but vid to be present
  3. Actually doing a redirect instead of rewrite - you can take out the R=301, to change that.

Sources:

  1. Subfolder to Subdomain
  2. Query Strings in Rewrites
  3. Domain Name in Rewrites
Community
  • 1
  • 1
Chris
  • 359
  • 1
  • 8
  • Thank you but it does not work for me. There is something I did not mention it which is : the .htaccess file will be inside the folder (v) and one more thing my website is running using WordPress so there is another .htaccess which is used for wordpress and because of that I will put it inside the (v) folder so the codes will be applied on this folder only – Kaito-Kaito Jul 17 '16 at 00:16
  • @Kaito-Kaito that does change things a bit. I have a rough idea of how to modify the rules; I'll replicate that situation on my server and update my answer as soon as I have some time. Meanwhile, you may want to edit your question and add those details for anyone else that may choose to answer. – Chris Jul 20 '16 at 13:24
  • @Kaito-Kaito I've updated my answer based on the above information – Chris Aug 08 '16 at 01:16