简体   繁体   中英

.htaccess redirect to subdomain only for homepage (OpenCart)

I want to redirect from mydomain.com to shop.mydomain.com but I also want to make this redirect work ONLY for the main page. It's an Opencart page so all the pages have urls similar to http://shop.mydomain.com/index.php?route=information/information&information_id=14 so making a rule for the index file only is a no go from my point of view. Since this project is a code spaghetti and has both OpenCart pages and static pages I need to keep the old URLs (without the subdomain) in working condition.

Looked up similar topics but all of them do the exact opposite thing, redirect from domain to subdomain or do the same thing but render my static pages useless so I ended up in using a very bad temporary method as shown below.

 <meta http-equiv="refresh" content="0;URL='http://shop.example.com/index.php?route=information/information&information_id=15'" /> 

Thank you very much and I hope I won't get loads of duplicate votes until you read and find something that is truly a duplicate.

You can use this in your /.htaccess file:

Options +FollowSymLinks

RewriteEngine On

# Redirect root to shop.example.com
RewriteRule ^/?$ http://shop.example.com/index.php?route=information/information&information_id=14 [R,L]

# Route to PHP files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

To make the redirect permanent, change [R,L] to [R=301,L] .

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