如何重定向使用的.htaccess? [英] How to redirect using .htaccess?

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

问题描述

我需要我的网站,从这个URL重定向:

  mysite.com/old/dir/param1/param2 / ...
 

  mysite.com/dir/param1/param2 / ...
 

我需要保持的参数,可以只在url中删除旧。

我怎么能这样规则添加到我的.htaccess?

谢谢!

下面是我的.htaccess:

 < IfModule mod_rewrite.c>
    RewriteEngine叙述上

的RewriteBase /
    的RewriteCond%{} REQUEST_FILENAME!-d
    的RewriteCond%{} REQUEST_FILENAME!-f
    重写规则^(。*)$的index.php?/ $ 1 [QSA,L]

    重写规则^老/ DIR /(.*)mysite.com/dir/$1 [R = 301,L]
< / IfModule>
 

解决方案

有关的权利的规则是

和我所有的其他规则之前,把它。所以,我的.htaccess如下:

 < IfModule mod_rewrite.c>
    RewriteEngine叙述上

    重写规则^老/ DIR /(.*)/ DIR / $ 1 [R = 301,L]


    的RewriteCond%{} REQUEST_FILENAME!-d
    的RewriteCond%{} REQUEST_FILENAME!-f
    重写规则^(。*)$的index.php?/ $ 1 [QSA,L]
< / IfModule>
 

不管怎样,谢谢! :)

I need my site to redirect from this url:

mysite.com/old/dir/param1/param2/...

to

mysite.com/dir/param1/param2/...

I need to keep the params, just remove the "old" in the url.

How can I add this rule to my .htaccess?

Thanks!!!

Here's my .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On

RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

    RewriteRule ^old/dir/(.*) mysite.com/dir/$1 [R=301,L]
</IfModule>

解决方案

The right rule for it was

and I had to place it before all the other rules. So my .htaccess looks like:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^old/dir/(.*) /dir/$1 [R=301,L]


    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>

Thanks anyway! :)

这篇关于如何重定向使用的.htaccess?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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