简体   繁体   English

301使用.htaccess重定向到php文件

[英]301 redirect using .htaccess for a php file

We had a website redesign and some of the pages no longer exist. 我们对网站进行了重新设计,并且某些页面不再存在。 I did 301 redirects on most of the old pages, but rather than have all of those old pages still in my folders I wanted to redirect everything in the .htaccess file instead. 我在大多数旧页面上执行了301重定向,但是我不想将所有这些旧页面都保留在我的文件夹中,而是想重定向.htaccess文件中的所有内容。 Below is my whole .htaccess file as of right now. 下面是截至目前我的整个.htaccess文件。 The redirect of an html file to a php file works fine, but trying to redirect from a php file to a php file is not working. 将html文件重定向到php文件可以正常工作,但是尝试从php文件重定向到php文件不起作用。 I have tried leaving the first part of the url (up to the .com) off of the new page but I still get a 404 error. 我尝试将URL的第一部分(直到.com)从新页面上移开,但仍然出现404错误。 I have tried multiple other pages and get the same results every time, directing from html to php works but from php to php doesn't. 我已经尝试了多个其他页面,每次都得到相同的结果,从html到php的工作原理有效,但是从php到php却没有。 Any suggestions? 有什么建议么?

Options +FollowSymLinks
RewriteEngine on
Redirect 301 /folder1/page1.php http://www.example.com/folder2/page2.php
Redirect 301 /folder1/page1.html http://www.example.com/folder2/page2.php
RewriteEngine On
RedirectMatch 301 folder1/(.*) folder2/$1
RewriteRule ^(.*)\.html$ $1.php [L]

Edit: 编辑:

RedirectMatch takes everything in folder1 and redirects to folder2 RedirectMatch接收folder1中的所有内容,然后重定向到folder2

RewriteRule then takes all html file extensions and rewrites them to php RewriteRule然后获取所有html文件扩展名并将其重写为php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM