.htaccess 组合htaccess重定向规则

.htaccess 组合htaccess重定向规则,.htaccess,url-rewriting,.htaccess,Url Rewriting,我有两个单独的htaccess,我需要将它们合并成一个,但我不知道如何做到这一点。以下是我的访问权限: 一, 我应该把它们放在同一个模块中吗?我已经试过了,但没用。 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} \ //([^\?\ ]*) RewriteRule ^ /folder/%1 [L,R=301] RewriteRule ^index\.php$ -

我有两个单独的htaccess,我需要将它们合并成一个,但我不知道如何做到这一点。以下是我的访问权限:

一,

我应该把它们放在同一个模块中吗?我已经试过了,但没用。


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \ //([^\?\ ]*)
RewriteRule ^ /folder/%1 [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
重新启动发动机 重写基/ 重写条件%{U请求}\/([^\?\]*) 重写规则^/文件夹/%1[L,R=301] 重写规则^index\.php$-[L] 重写cond%{REQUEST_FILENAME}-F 重写cond%{REQUEST_FILENAME}-D 重写规则/index.php[L]
这样做:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# remove multiple slashes
RewriteCond %{REQUEST_URI} ^(.*?)//+(.*)$
RewriteRule ^ %1/%2 [R=302,L,NE]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

重新启动发动机
重写基/
#删除多个斜杠
RewriteCond%{REQUEST_URI}^(.*)/+(.*)重写$
重写规则^%1/%2[R=302,L,NE]
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则。index.php[L]
  • 在新浏览器中进行测试,以避免旧的301缓存
  • 如果发生重定向循环,则打开Firebug并访问带有2个斜杠的URL,然后签入“网络”选项卡以获取重定向

我这样做了,但恐怕不行。我仍然收到一个重定向循环错误。我收到21个指向同一URL的重定向。您在浏览器中输入的URL是什么?是否有更多规则,或者这是唯一的代码?我输入了mydomain.com//somepage,所有重定向都是针对同一页面的。我没有任何其他规则,只有你发布的规则。嗯,你知道,我想这是因为我的URL中有特殊字符,因为在重定向后,我得到了一个404错误,如果我看URL是类似mydomain.com/%E3%82%A2%E3%82%A4%E3%83%BB%E3%/好的,有特殊字符的示例URL是什么?您还可以在
NE
标志旁边添加
B
标志。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \ //([^\?\ ]*)
RewriteRule ^ /folder/%1 [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# remove multiple slashes
RewriteCond %{REQUEST_URI} ^(.*?)//+(.*)$
RewriteRule ^ %1/%2 [R=302,L,NE]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>