php - .htaccess 重定向到仅用于主页的子域 (OpenCart)

标签 php .htaccess mod-rewrite redirect opencart

我想从 mydomain.com 重定向到 shop.mydomain.com,但我也想让此重定向仅适用于主页。这是一个 Opencart 页面,因此所有页面的 URL 类似于 http://shop.mydomain.com/index.php?route=information/information&information_id=14因此,从我的角度来看,只为索引文件制定规则是行不通的。由于这个项目是一个代码意大利面,并且有 OpenCart 页面和静态页面,我需要保持旧 URL(不带子域)处于工作状态。

查找了类似的主题,但它们都做了完全相反的事情,从域重定向到子域或做同样的事情但使我的静态页面无用,所以我最终使用了一个非常糟糕的临时方法,如下所示。

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

非常感谢您,我希望在您阅读并找到真正重复的内容之前我不会收到大量重复的投票。

最佳答案

您可以在 /.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

要使重定向永久生效,请将 [R,L] 更改为 [R=301,L]

关于php - .htaccess 重定向到仅用于主页的子域 (OpenCart),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30191465/

相关文章:

php curl - 需要使用 curl 提供对 protected 目录的访问

.htaccess - 使用相对重写URL从文件夹内进行301重写

apache - Nginx 对 cms 后端的重写规则

regex - 如何重定向完整域 URL 并使用 htaccess 删除子文件夹

.htaccess - mod_rewrite 在大写目录上失败

php - 将多个查询字符串转换为 php 中的 seo 友好 url

php - Zend 框架 2 项目示例

php - sql 结果显示在 phpmyadmin 上,但不将记录返回到我的网站

javascript - API 在 MVC 中扮演什么角色?

.htaccess - 将页面从旧站点重定向到新站点 - 一个接一个