php - Opencart 重定向到 www.localhost.com

标签 php mysql apache .htaccess opencart

我已经从 live 站点下载了 OpenCart 项目,并放入了 localhost。 更改了 catalog/config.php 和 admin/config.php

问题是,当我输入 url: localhost/xyz 时,它会重定向到 www.localhost.com

config.php:

<?php
define('HTTP_SERVER', 'http://localhost/xyz/');
define('HTTPS_SERVER', 'http://localhost/xyz/');

define('DIR_APPLICATION', 'C:\xxampp\htdocs\xyz/catalog/');
define('DIR_SYSTEM', 'C:\xxampp\htdocs\xyz/system/');
define('DIR_DATABASE', 'C:\xxampp\htdocs\xyz/database/');
define('DIR_LANGUAGE', 'C:\xxampp\htdocs\xyz/catalog/language/');
define('DIR_TEMPLATE', 'C:\xxampp\htdocs\xyz/catalog/view/theme/');
define('DIR_CONFIG', 'C:\xxampp\htdocs\xyz/system/config/');
define('DIR_IMAGE', 'C:\xxampp\htdocs\xyz/image/');
define('DIR_CACHE', 'C:\xxampp\htdocs\xyz/system/cache/');
define('DIR_DOWNLOAD', 'C:\xxampp\htdocs\xyz/download/');
define('DIR_LOGS', 'C:\xxampp\htdocs\xyz/system/logs/');

define('DB_DRIVER', 'mysql');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'xyz_abc');
define('DB_PREFIX', 'xyz_');
?>

.htaccess:

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled. 
# 2. In your opencart directory rename htaccess.txt to .htaccess.
# For any support issues please visit: http://www.opencart.com
Options +FollowSymlinks
# Prevent Directoy listing 
Options -Indexes
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you     folder it does run in ie. / becomes /shop/ 

#RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

### Additional Settings that may need to be enabled for some servers 
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following     settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off
# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off
# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M
# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product  options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none

以上文件是 .htaccess 文件,已尝试了大部分相关代码,但仍无法正常工作。

最佳答案

您的 RewriteBase 在您的 .htaccess 文件中是错误的。按照你的说法,你今天的代码是这样的:

#RewriteBase /

但它应该是这样的:

RewriteBase /xyz/

请注意,您必须检查 mod_rewrite 是否在您的 Apache 配置中打开,因为 AllowOverride 指令(All文件信息)。此外,如果您的安装在根目录中有一个 .htaccess 文件,它可能是相关的。

关于mod_rewrite配置,我推荐this post (葡萄牙语)或 this answer (英文)。

关于php - Opencart 重定向到 www.localhost.com,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21423881/

相关文章:

php - the_content 过滤器将自定义字段添加到 JSON 响应

MySQL获取与其他表匹配的前10项以对它们进行分组

java - HttpClient 只响应一行 XML

javascript - 将 PHP 整数传递给 JavaScript

php - 在 Eloquent Laravel 中为 Between 编写原始查询

javascript - 删除表中带有复选框的数据

java - 在 MySQL JDBC 中使用批处理 SQL 命令

MYSQL Foreign Key Errno (150) 无法创建表

php - 如何在没有连续请求的情况下创建 PHP 聊天应用程序?

regex - .htaccess:重定向除一个页面之外的所有页面