【问题标题】:Redirecting certain URL to another in HTACCESS将某个 URL 重定向到 HTACCESS 中的另一个 URL
【发布时间】:2017-08-09 06:41:08
【问题描述】:

好的,这里很多。我最近更改了域名,我需要重定向很多东西。首先..

所有页面

http://helloarchie.blue(旧域名)

需要重定向到

http://helloarchie.co(新域)。

到目前为止,只有通过 cPanel 设置的主页重定向。

我还需要使用此 URL 重定向所有图像:

http://kaye.at/img/

http://helloarchie.co/img/

这是我目前的 htaccess。

Options -indexes

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?/$1 [L] 

# RewriteCond %{HTTP_HOST} ^(www\.)?kaye\.at$
RewriteRule ^(.+\.png|gif|pdf|jpg|doc)$ http://helloarchie.co/$1 [NC,L,R]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>

RewriteCond %{HTTP_HOST} ^www\.helloarchie\.co [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^(.*)$ http://helloarchie.co/$1 [L,R=301]

<Files 403.shtml>
order allow,deny
allow from all
</Files>

【问题讨论】:

  • RewriteCond %{HTTP_HOST} ^(www\.)?kaye\.at$ RewriteRule ^(.+\.png|gif|pdf|jpg|doc)$ helloarchie.co/$1 [NC,L ,R] 仅重定向 png、git、pdf、jpg、doc 文件。那是你要的吗 ?有什么问题?
  • 我已经更好地澄清了我的查询(希望如此)。
  • RewriteCond %{HTTP_HOST} ^www\.helloarchie\.co [NC] ==> 应该是 RewriteCond %{HTTP_HOST} ^www\.helloarchie\.blue [NC]
  • 适用于主页,但不适用于单个页面,即。 helloarchie.blue/press
  • 如果你删除了 3 "RewriteCond %{REQUEST_URI} ..." ?

标签: .htaccess redirect dns


【解决方案1】:

您需要重新排序规则:

<Files 403.shtml>
order allow,deny
allow from all
</Files>

Options -indexes

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(?:www\.)?helloarchie\.blue$ [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ [NC]
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ [NC]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[\w-]+$ [NC]
RewriteRule ^ http://helloarchie.co%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTP_HOST} ^(www\.)?kaye\.at$
RewriteRule ^(.+\.png|gif|pdf|jpe?g|doc)$ http://helloarchie.co/$1 [NC,L,R=301]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>

【讨论】:

  • @KayeHuett:这对你有帮助吗?
猜你喜欢
  • 2013-08-04
  • 2012-12-04
  • 2015-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-13
  • 2021-07-22
相关资源
最近更新 更多