英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论