重写HTACCESS不重新定向的规则

发布于 2025-01-18 09:28:44 字数 1402 浏览 2 评论 0原文

我写了一个 RewriteRule 似乎不起作用。

该文件看起来像这样:

<IfModule mod_rewrite.c>
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(\/[parteneri]+)\/+([a-zA-Z\-\s]+)\/+([\/a-zA-Z\-\s]+)* index.php [L]
</IfModule>

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

我试图开始工作的行是这样的:

RewriteRule ^(\/[parteneri]+)\/+([a-zA-Z\-\s]+)\/+([\/a-zA-Z\-\s]+)* index.php [L]

正则表达式规则应该匹配以下格式的任何内容: /parteneri/event/ - 我确实知道正则表达式规则也匹配像这样的模式 /parteneri/events/asdf/adsf,但这很好,因为我仍然希望将其重定向到索引页面。

我已经使用正则表达式检查器在线检查了正则表达式,并且模式似乎确实匹配。 .htaccess 文件位于 WordPress 网站上,我试图将包含 parteneri/post_type_name/ 的每个链接重定向回索引页面。

编辑
我在另一个网站上有一个类似的 RewriteRule 可以工作,但只有这个也有参数。

RewriteRule ^([location]+)\/+([a-zA-Z\-\s]+)\/+([/a-zA-Z\-\s]+)*$ property-search.php?property-location=$2&sale-rent=$3 [L]

我缺少什么?

I have written a RewriteRule that doesn't seem to work.

The file looks like this:

<IfModule mod_rewrite.c>
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(\/[parteneri]+)\/+([a-zA-Z\-\s]+)\/+([\/a-zA-Z\-\s]+)* index.php [L]
</IfModule>

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

The line I am trying to get to work is this one:

RewriteRule ^(\/[parteneri]+)\/+([a-zA-Z\-\s]+)\/+([\/a-zA-Z\-\s]+)* index.php [L]

The Regex rule is supposed to match anything in the format: /parteneri/event/ - I do know that the regex rule matches patterns like this one as well /parteneri/events/asdf/adsf, but that is fine as I would still like it to be redirected to the index page.

I have checked the regex online with a regex checker and the patterns do seem to match. The .htaccess file is on a wordpress website and I am trying to redirect every link that has parteneri/post_type_name/ back to the index page.

Edit

I have a similar RewriteRule on another website that works, only this one has parameters as well.

RewriteRule ^([location]+)\/+([a-zA-Z\-\s]+)\/+([/a-zA-Z\-\s]+)*$ property-search.php?property-location=$2&sale-rent=$3 [L]

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文