htaccess的重写规则重写301重定向 [英] .htaccess rewrite rule rewriting 301 redirects

查看:140
本文介绍了htaccess的重写规则重写301重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我的.htaccess重定向。我从我的网址(我使用PHP框架)同时拥有重写规则删除,并且还301重定向从旧网页重定向的index.php /?

 #START改写
RewriteEngine叙述上
选项​​-Indexes
选项​​+的FollowSymLinks
的RewriteCond $ l ^(指数\ .PHP |资产)!
重写规则^(。*)$ /index.php?/$1 [L]

#301重定向
重定向301 /oldpage.html http://www.example.com/old_page
重定向301 /page.html http://www.example.com/page
重定向301 /page-that-no-longer-exists.html http://www.example.com/
 

我不能重命名我的.html文件与其他重写规则的某些页面不匹配新的页面,和一些其他的.html页面重定向到首页 - 因此,301重定向

所以,重写规则的原因,第一个301重定向将直接以

http://www.example.com/old_page?/old_page.html

而不是

http://www.example.com/old_page

我试图重新排序的.htaccess文件的内容(这什么都不做),设置改写为off的改写(停靠301的工作)之后,写具体的重写规则为每301(其中没有工作)。

我敢肯定,我失去了一些东西。干杯。

解决方案

好了,我想出了几个解决方案。

首先是发送重定向在示例

 重定向301 /oldpage.html http://www.example.com/index.php?/old_page
 

这不适用于重写删除的index.php?,但它的工作。

第二个解决方法是编辑改写条件排除任何的.php或.html文件:

 的RewriteCond $ l ^([A-ZA-Z1-9 \  -  \ _ /] * \ PHP $ |!资产| [A-ZA-Z1-9 \  -  \ _ /] * \。HTML $)
 

这也exluce结尾以.php或.html的任何网址,这意味着重写将无法正常工作,而你的框架将打破,但只要你远离你应该没问题。

I have a problem with my .htaccess redirects. I have both a rewrite rule to remove the "index.php?/" from my URLs (I'm using a PHP framework), and also 301 redirects redirecting from old pages:

# START THE REWRITE
RewriteEngine on
Options -Indexes
Options +FollowSymLinks
RewriteCond $1 !^(index\.php|assets)
RewriteRule ^(.*)$ /index.php?/$1 [L]

# 301 REDIRECTS
Redirect 301 /oldpage.html http://www.example.com/old_page
Redirect 301 /page.html http://www.example.com/page
Redirect 301 /page-that-no-longer-exists.html http://www.example.com/

I can't rename my .html files with another rewrite rule as some of the pages don't match the new pages, and some other .html pages are redirecting to the home page - hence the 301 redirects.

And so, because of the rewrite rule, the first 301 redirect will direct to

http://www.example.com/old_page?/old_page.html

instead of

http://www.example.com/old_page

I have tried reordering the contents of the .htaccess file (which does nothing), setting the rewrite to "off" after the rewrite (which stops the 301's working) and writing specific rewrite rules for each 301 (none of which worked).

I'm sure i'm missing something. Cheers.

解决方案

OK, I've come up with a couple of solutions.

The first is to send the redirect in the example to

Redirect 301 /oldpage.html http://www.example.com/index.php?/old_page

This does not apply the rewrite removing the "index.php?", but it does work.

The second work around is to edit the rewrite conditions to exclude any .php or .html files:

RewriteCond $1 !^([a-zA-Z1-9\-\_/]*\.php$|assets|[a-zA-Z1-9\-\_/]*\.html$)

This may also exluce any URLs that end in .php or .html, meaning the rewrite won't work, and your framework will break, but as long as you stay away from that you should be ok.

这篇关于htaccess的重写规则重写301重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆