简体   繁体   中英

Redirect all traffic to one sub-directory with httpd.conf

I have a httpd.conf file with many domains configured on my server. I need to redirect an old directory on just one website to a new directory.

Basically, when a user accesses any page in the dir domain.com.au/store , I want them to be redirected to domain.com.au/shop .

I don't want the redirect to include the old webpath, so any old URL needs to redirect only to the domain.com.au/shop page, not to /shop/old_webpath .

I've tried many redirect entries from around the web, none seem to work correctly, as they all redirect to /shop/old_webpath , not just /shop .

Can any apache minds help?

Try this in .htaccess file:

Options +FollowSymLinks -MultiViews

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^store/(.*)$ \/shop
</IfModule>

Update for virtual host in apache configuration for domain.com.au :

<VirtualHost *:80>
    # ...
    <Directory "[your_path]">
        # ...
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{HTTP_HOST} ^domain\.com\.au$ [NC]
        RewriteRule ^store/(.*)$ \/shop
    </Directory>
</VirtualHost>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM