Task: convert the query string from http://anything.example.com/querystring to http://example.com/anything/querystring

And I also need to convert some querystring in the following way: nikon/123/something => ?section=nikon&id=123 , and leave the remaining strings unchanged.

In part, everything works for me with this htaccess:

 RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*)\.example\.com [NC] RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ %1/index.php?section=$1&id=$2 [L,QSA] 

But this only works for queries matching the pattern in the third line. Those. if I place, for example, sitemap.xml in the folder www/anything/sitemap.xml , then I can not request it by the URL anything.example.com/sitemap.xml - displayed Not found

I have more templates, I don’t specifically list them here so as not to clutter the issue with excess.

I would also add that I never managed to make a separate template for sitemaps. It did not work ...

    1 answer 1

    It worked. This is what I ended up with:

    Root .htacces (/homewww/.htaccess):

     RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*)\.example\.com RewriteRule ^(.*)$ %1/$1 [L,QSA] 

    This rewrite turns URLs like http://anysubdomain.example.com/anystring into http://example.com/anysubdomain/anystring

    Next, each .htaccess folder is placed (/homewww/anysubdomain/.htaccess):

     RewriteEngine on RewriteRule ^([^/.]+)/?$ index.php?section=$1 [L,QSA,NC] RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?section=$1&page=$2 [L,QSA,NC] RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ index.php?section=$1&id=$2 [L,QSA,NC] 

    Thus, this rewrite will convert URLs depending on the number of parameters into one of three requests. In this case, requests that do not fall under the template are also passed and, for example, the file /homewww/anysubdomain/sitemaps/sitemap.xml becomes available on request http://anysubdomain.example.com/sitemaps/sitemap.xml

    As required. Good luck to all!