简体   繁体   English

htaccess 从空文件夹重定向到另一个目录

[英]htaccess redirect from empty folder to another directory

I have an empty directory at www.test.com/ar/carprices .我在www.test.com/ar/carprices有一个空目录。

I would like to redirect all urls from我想重定向所有网址

www.test.com/ar/carprices

to

www.test.com/carprices/ar

I have placed the following .htaccess in the www.test.com/ar/carprices folder but it does not work:我已将以下 .htaccess 放在www.test.com/ar/carprices文件夹中,但它不起作用:

RewriteBase /
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule (.*)ar/carprices(.*) $1carprices/ar$2 [L,R=301,NC]

You can also use RedirectMatch here :您也可以在此处使用 RedirectMatch :

RedirectMatch ^/ar/carprices/(.*)$ /carprices/ar/$1

Will redirect /ar/carprices/ to /carprices/ar将 /ar/carprices/ 重定向到 /carprices/ar

For internal url redirection ,use :对于内部 url 重定向,请使用:

In htaccess :在 htaccess 中:

RewriteEngine on

RewriteRule ^ar/carprices/(.*)$ /carprices/ar/$1 [NC,L]

leading slash is not matched in RewriteRule in htaccess context, that is why I remove it from the regex pattern.在 htaccess 上下文中的 RewriteRule 中前导斜杠不匹配,这就是我将其从正则表达式模式中删除的原因。

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

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