[英]htaccess 301 redirect to url without passing subdirectories
I'm trying to redirect a URL like this: 我正在尝试重定向这样的网址:
http://domain.com/word/baseball/cat/
To a URL like this: 对于这样的网址:
http://domain.com/otherpage/
The htaccess line I'm using is: 我正在使用的htaccess行是:
redirect 301 /word/baseball/cat/ http://domain.com/otherpage/
But the resulting URL after the redirect ends up being: 但重定向后生成的URL最终为:
http://domain.com/otherpage/baseball/cat/
I'd like to redirect the full URL to the new URL without passing the 'baseball/cat/' subdirectories, so that we hopefully end up with the URL: 我想将完整的URL重定向到新的URL 而不传递'baseball / cat /'子目录,因此我们希望最终得到这个URL:
http://domain.com/otherpage/
This is for a website with approximately 500 URLs like this that need to be redirected to entirely different URLs. 这适用于具有大约500个此类网址的网站,需要将其重定向到完全不同的网址。
I appreciate any help in advance! 我提前感谢任何帮助!
If you're doing this with PHP, an alternate way could be the following, however it may not be too effective: 如果您使用PHP执行此操作,则可以使用以下替代方法,但这可能不太有效:
header('Location: http://newurl.com');
Also try: 还试试:
RewriteEngine on
RewriteRule "/page1" "http://example.com/page1" [R]
Put your .htaccess
file at the top level directory, in your DOCUMENT_ROOT
. 将
.htaccess
文件放在DOCUMENT_ROOT
中的顶级目录中。 The file should at least contain these rewrite instructions: 该文件至少应包含以下重写指令:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</IfModule>
Now all non existing file and directory urls that come to the site will go to index.php
. 现在,访问该站点的所有非现有文件和目录URL都将转到
index.php
。 Within index.php
put a routing mechanism. 在
index.php
放了一个路由机制。 A very simple one would look like this: 一个非常简单的看起来像这样:
index.php 的index.php
$rurl = '';
switch ($_SERVER['REQUEST_URI']) {
case '/word/baseball/cat/': $rurl = '/otherpage1/'; break;
case '/word/baseball/dog/': $rurl = '/otherpage2/'; break;
case '/word/baseball/rat/': $rurl = '/otherpage3/'; break;
}
if (!empty($rurl)) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$rurl);
exit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.