.htaccess 重定向并添加变量

发布于 2024-12-27 06:35:36 字数 983 浏览 3 评论 0原文

我们的客户横幅活动今天启动,但已存入错误的网址。

所以我尝试重定向

website.com/wheels/?lang=en&sel=540

website.com/wheels/index.html?lang=en&sel=540

我尝试将 .htaccess 放入包含以下内容的文件夹中:

RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/?$  index.html?lang=$1&sel=$2

但它不起作用。有人知道我做错了什么吗?

编辑

我在根目录中发现了一个现有的.htaccess。它包含以下代码:

RewriteEngine On
RewriteBase /
RewriteRule ^(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)/ - [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* /index.php [L]

如果我添加以下代码,则不会发生任何事情:

RewriteCond %{QUERY_STRING} ^lang=en&sel=[0-9]+(&|$) [NC]
RewriteRule ^(wheels)/$ /$1/index.html [R=301,L,NC]

顺便说一句,lang 不是静态的,它可以是 en 或 de。

our clients banner campain lauched today an the wrong url has been deposited.

So i try to redirect

website.com/wheels/?lang=en&sel=540

to

website.com/wheels/index.html?lang=en&sel=540

I tryed to put a .htaccess in the folder wheels which contains following:

RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/?$  index.html?lang=$1&sel=$2

But it doesn't work. Anyone has an idea, what i'm doing wrong?

EDIT

I found a existing .htaccess in the ROOT. It contains following code:

RewriteEngine On
RewriteBase /
RewriteRule ^(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)/ - [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* /index.php [L]

If I add the code folling code, nothing happens:

RewriteCond %{QUERY_STRING} ^lang=en&sel=[0-9]+(&|$) [NC]
RewriteRule ^(wheels)/$ /$1/index.html [R=301,L,NC]

Btw, lang is not static, it can be en or de.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

‖放下 2025-01-03 06:35:36

尝试将其添加到网站根目录中的 .htaccess 中。默认情况下携带查询字符串参数。

RewriteEngine on
RewriteBase /

RewriteRule ^wheels/$  /wheels/index.html [R=301,L,NC]

Try adding this to the .htaccess in the root directory of your website. The querystring parameters are carried through by default.

RewriteEngine on
RewriteBase /

RewriteRule ^wheels/$  /wheels/index.html [R=301,L,NC]
谈下烟灰 2025-01-03 06:35:36

在您的 ROOT .htaccess 中使用它:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} ^lang=en&sel=[0-9]+(&|$) [NC]
RewriteRule ^(wheels)/$ /$1/index.html [R=301,L,NC]

Use this in your ROOT .htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} ^lang=en&sel=[0-9]+(&|$) [NC]
RewriteRule ^(wheels)/$ /$1/index.html [R=301,L,NC]
飘落散花 2025-01-03 06:35:36

您还可以通过在现有 RewriteRule 前面添加额外的 RewriteCond 来实现此目的

RewriteCond $0 !^wheels/

You could also do this by adding an extra RewriteCond in front of the existing RewriteRule

RewriteCond $0 !^wheels/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文