htaccess 和内部文件夹的问题

问题描述 投票:0回答:1

我有一个网站域,根目录中安装了 WordPress,我们将其命名为: mywebsite.com.

我还有一个文件夹,其中包含一个独立于 WordPress 运行的应用程序,即: mywebsite.com/tool

我需要更新 htaccess 文件,以便将文件夹内的任何链接从具有 WWW 更改为不具有并保留目录和参数

问题是当我转到应用程序目录内的某个路线时,例如这个 “https://www.mywebsite.com/tool/dfy/index.php?campaign=33&token=1”跳转到“https://mywebsite.com/dfy/?campaign=33&token=1”并给出错误

它实际上是用非 www 更新 www,但不知何故它忘记了“工具”和 index.php...这很奇怪。

根目录下的htaccess是这样的:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond $1 !^(/tool)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [L,R=301]
</IfModule>

第二部分与保留文件夹和内部路由有关,但正如我之前提到的,它不起作用。

我什至在 /tool 中添加新的 htaccess 文件,甚至在 /tool/dfy 上添加以下内容:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com [NC]
RewriteRule ^(.*)$ https://mywebsite.com/$1 [L,R=301]

但现在我不确定哪个 htaccess 会统治其他人......

任何建议,帮助,我们将不胜感激,谢谢!

最终目标: 转换此链接: “https://www.mywebsite.com/tool/dfy/index.php?campaign=33&token=1” 进入这个: “https://mywebsite.com/tool/dfy/index.php?campaign=33&token=1” 根目录中有一个 htaccess WP 文件。

按照评论中的建议进行更新:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Exclude the "tool" folder from the previous rule
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com [NC]
RewriteRule ^tool/(.*)$ http://mywebsite.com/tool/dfy/$1 [L,R=301]


RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond $1 !^(/tool)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

仍然无法工作...

.htaccess
1个回答
0
投票

完成! 最终htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Exclude the "tool" folder from the previous rule
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com [NC]
RewriteRule ^tool/(.*)$ http://mywebsite.com/tool/$1 [L,R=301]


RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
© www.soinside.com 2019 - 2024. All rights reserved.