【发布时间】:2021-12-07 09:39:18
【问题描述】:
我一直在尝试使用 htaccess 文件将旧 url 重定向到新域 url。带有 301 重定向代码。但旧网址与新域名网址相同。我试过以下代码 Htaccess 文件
##
# @package Joomla
# @copyright Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.
# @license GNU General Public License version 2 or later; see LICENSE.txt
##
##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that disallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
##
## No directory listings
IndexIgnore *
## Can be commented out if causes errors, see notes above.
Options +FollowSymlinks
Options -Indexes
## Mod_rewrite in use.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule (.*)$ http://www.example1.com/$1 [R=301,L]
#for http to https
##RewriteCond %{HTTPS} !on
##RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
#for www
##RewriteCond %{HTTP_HOST} !^www\.
##RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the
operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via
URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root
homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects
##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##
# RewriteBase /
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
Redirect 301 /x-ee-ee/sub-category/ererrre/
https://www.example1.com/category/exurl
输出 当我输入地址https://www.example.com/x-ee-ee/sub-category/ererrre/ 时,它会重定向到https://www.example1.com/x-ee-ee/sub-category/ererrre/
预期输出 当我输入地址https://www.example.com/x-ee-ee/sub-category/ererrre/ 时应该重定向到 https://www.example1.com/category/exurl
【问题讨论】:
-
它似乎没有做任何事情。你到底把这条规则放在哪里?你有现有的指令吗?
-
重定向网址重定向到相同的网址而不是新的网址
-
您要的网址是什么? (我看到您刚刚编辑了您的问题以更改“输出”中的域 - 这是否意味着您正在请求不同的域?)
-
是的,从旧域旧 url 到新域 url 不重定向它被重定向到与新域 url 相同的旧域
-
那么,您请求的实际 URL 是什么?您的
.htaccess文件中是否有现有指令?您的子目录中还有其他.htaccess文件吗?
标签: .htaccess