Search code examples
php.htaccessmod-rewritehttp-redirectslash

Htaccess redirect if there's nothing after slash


If my website is www.site.com, and there's a shop at www.site.com/shop, how do I make it so that going to shop.site.com, if it doesn't have anything after / (for example shop.site.com/someItem wouldn't redirect) would redirect to www.site.com/shop?

Right now going to shop.site.com/someShopItem redirect correctly to www.site.com/someShopItem, and I need it to stay this way, only change the shop.site.com -> www.site.com/shop

Thank You


Solution

  • You can use this rule in root .htaccess of shop.site.com:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^shop\.domain\.com$ [NC]
    RewriteRule ^/?$ http://www.domain.com/shop/ [L,NC,R=302]