简体   繁体   English

.htaccess仅重定向到主页的子域(OpenCart)

[英].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. 我想从mydomain.com重定向到shop.mydomain.com,但我也想使此重定向仅对主页有效。 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. 这是一个Opencart页面,因此所有页面的URL都类似于http://shop.mydomain.com/index.php?route=information/information&information_id=14,因此仅对索引文件制定规则对我来说是不可行的视图。 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. 由于此项目是代码面条,并且同时具有OpenCart页面和静态页面,因此我需要保持旧的URL(无子域)处于工作状态。

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: 您可以在/.htaccess文件中使用它:

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] . 要使重定向永久生效,请将[R,L]更改为[R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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