如何重定向使用的.htaccess?重定向、htaccess

2023-09-02 10:09:55 作者:听一曲离殇、

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

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

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

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

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

谢谢!

WordPress博客301重定向及.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! :)