将旧域名上带有 .html 扩展名的 URL 重定向到子域名。

huangapple go评论46阅读模式
英文:

Redirect old domain url with .html extension to subdomain

问题

你想要使用.htaccess将所有以.html结尾的URL重定向到子域名,如下所示:

  • http://example.com/video.html
  • http://example.com/gallery/first-galery.html
  • http://example.com/category/month/12/news.html

重定向到:

  • http://archive.example.com/video.html
  • http://archive.example.com/gallery/first-galery.html
  • http://archive.example.com/category/month/12/news.html

在新网站上,我已经安装了WordPress,并且希望处理所有HTTP请求,因为旧网站没有使用HTTPS,最好避免与WordPress发生冲突。

英文:

Hi would like to redirect with .htaccess all URLs that end with .html to subdomains like

  • http://example.com/video.html
  • http://example.com/gallery/first-galery.html
  • http://example.com/category/month/12/news.html

to

  • http://archive.example.com/video.html
  • http://archive.example.com/gallery/first-galery.html
  • http://archive.example.com/category/month/12/news.html

On the new site, I have installed WordPress and I want to process all HTTP requests since the old site didn't use HTTPS ad it would be good to avoid collision WP.

答案1

得分: 2

这取决于您使用的Web服务器。2个常用的Web服务器是Apache和Nginx。

如果您使用Apache,您可以在根目录中创建.htaccess文件,并添加以下内容:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*)\.html$ http://archive.example.com/$1.html [R=301,L]

如果您使用Nginx,您需要更新配置文件以包括以下内容:

server {
    listen 80;
    server_name example.com;
    rewrite ^/(.*)\.html$ http://archive.example.com/$1.html permanent;
}

正如您所看到的,我们在Apache中使用了301重定向,在Nginx中使用了permanent,因为它们是最终的。

您还需要设置一个DNS记录来支持archive.example.com子域名。

英文:

This really depends on the web server you are using. 2 popular web servers are Apache and Nginx.

If you are using Apache, you can create .htaccess file in the root directory with the following:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*)\.html$ http://archive.example.com/$1.html [R=301,L]

If you are using Nginx, you need to update the configuration file to include the following:

server {
    listen 80;
    server_name example.com;
    rewrite ^/(.*)\.html$ http://archive.example.com/$1.html permanent;
}

As you can see, we are using 301 redirect in Apache and permanent in Nginx because they are final.

You will also need to have a DNS record set up for the archive.example.com subdomain

huangapple
  • 本文由 发表于 2023年5月14日 19:42:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247300.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定