AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[.htaccess](coding)

Martin Hope
oyvey
Asked: 2025-04-06 11:14:18 +0800 CST

子文件夹中的 .htaccess 提供错误参数

  • 5

我正在处理我网站中的一个子文件夹。该文件夹中的 .htaccess 包含以下两行:

RewriteEngine on
RewriteRule ^(.*)$                      page.php?id=$1 [L]

我的子文件夹中的 php 文件包含以下代码:

print_r($_GET);

当我转到以下页面时:

https://www.example.com/subfolder/ddd

我在屏幕上看到以下内容:

数组([id] => page.php)

我想要的是:

数组([id] => ddd)

我做错什么了?

.htaccess
  • 1 个回答
  • 27 Views
Martin Hope
stacky
Asked: 2025-02-26 23:04:46 +0800 CST

httaccess 将 Hubspot URL 重定向至 CMS

  • 5

我正在尝试实现部分 URL 重定向到 htaccess。

URL 应从以下位置重定向:

hs.bzb.domain.com/bzbwebprod/login?rout=modeDeta&mode=654321&arti=&farb=4321

到:

bzb.domain.com/bzbwebprod/#/login?rout=modeDeta&mode=654321&arti=&farb=4321

但最好的情况是

hs.bzb.domain.com/bzbwebprod/login?

将被重定向至

bzb.domain.com/bzbwebprod/#/登录?

使用其附带的查询(例如?rout=modeDeta&mode=654321&arti=&farb=4321 )。

尝试过:

RewriteEngine On

RewriteRule ^hs.bzb.domain.com/bzbwebprod/login?* bzb.domain.com/bzbwebprod/#/login?$0 [L,NE,NC,R=301]

由于我对 htaccess 没有太多经验,我只是阅读其他带有解决方案的主题,并尽力在https://htaccess.madewithlove.com/上找到正确的选项。

有人可以帮我一下吗?

.htaccess
  • 1 个回答
  • 30 Views
Martin Hope
AC1D
Asked: 2024-11-13 22:33:12 +0800 CST

我需要在 .htaccess 中将 /item/x 重定向到 /item/y

  • 5

我在 .htaccess 中有规则

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^item/(.*)/?$ item.php/$1 [L,NC]
RewriteRule ^([^\.]+)$ $1.php [L,NC]

重定向到 /item/page

我从商店中删除了一件商品,现在我需要将 /item/x 重定向到 /item/y

尝试过这种方式重定向,但没有成功

Redirect ^/item/x$ /item/y
Redirect https://testsite.org/item/x https://testsite.org/item/y
Redirect /item/x https://testsite.org/item/y
.htaccess
  • 1 个回答
  • 17 Views
Martin Hope
santa
Asked: 2024-10-25 01:21:07 +0800 CST

重写规则来解决 2 个用例

  • 5

我的 .htaccess 文件中有一个重写规则:

RewriteRule ^projects/?([a-zA-Z0-9-]+)?/?([a-zA-Z0-9-]+)?$ /projects/$1/seo.$2.php  

例如,以下规则运行良好,我想保持其原样:

URL: domain.com/projects/book/read-more opens /projects/book/seo.read-more.php page

此外,我需要修改它或添加另一条规则,以仅显示目录,如果地址以目录结尾,则在 index.php 文件中解析。

URL: domain.com/projects/book to open /projects/book/index.php page

我尝试将以下规则放在当前规则之上,但没有效果。

RewriteRule ^projects/?([a-zA-Z0-9-]+)?$ /projects/$1/index.php [NC,L]

我错过了什么?

.htaccess
  • 2 个回答
  • 17 Views
Martin Hope
Wajeeh Haider
Asked: 2024-09-27 16:30:25 +0800 CST

htaccess 重写规则 401

  • 5

我已将其插入到 WordPress 安装的 htaccess 文件中

RewriteRule wp-content/plugins/(.*\.php)$ - [R=404,L]

我正在使用 LSCWP,并且想尝试访客模式。

为此,我需要访问位于

wp-content/plugins/litespeed-cache/guest.vary.php

我喜欢尽可能紧密地运行网站,我该如何修改重写规则以以某种方式允许执行 litespeed 缓存目录中的“guest.vary.php”文件?

到目前为止,我只尝试删除重写规则,而且确实有效,但它使 wp 内容目录容易受到代码执行的攻击。

.htaccess
  • 1 个回答
  • 17 Views
Martin Hope
Attack68
Asked: 2024-09-17 23:55:43 +0800 CST

编辑或创建 .htaccess 文件以将文件夹重定向到页面

  • 5

我.htaccess在文件夹中有一个文件public_html,因此我的目录如下所示:

public_html
    = cgi-bin/
    = images/
    = other/
    - index.html
    - .htaccess

文件.htaccess重新路由www.example.com到example.com。我从网上复制了以下代码,到目前为止它可以正常工作:

# Remove www from any URLs that have them:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

现在,如果有人访问www.example.com/other或example.com/other出现禁止example.com/other/页面错误。我想将任何这些请求重新路由到:

  • example.com/other/sub/index.html

我如何扩展现有.htaccess文件(或在子文件夹中创建新文件)来实现这一点?(注意无需屏蔽浏览器栏中的任何地址)

感谢任何解决方案和简要解释...

.htaccess
  • 1 个回答
  • 23 Views
Martin Hope
MartinS
Asked: 2024-09-12 04:18:46 +0800 CST

我在子文件夹中调用了 PHP 文件,但 .htaccess 使用了奇怪的重写

  • 6

在根目录中我有文件:.htaccess 和 page.php 在 /test/ 子文件夹中我有文件:define_session.php 和 write_session.php

.htaccess 文件:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)?$ page.php?p1=$1&p2=$2&p3=$3 [L,QSA]
# www.example.com/parameter1/parameter2/parameter3/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)?$ page.php?p1=$1&p2=$2 [L,QSA]
# www.example.com/parameter1/parameter2/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ page.php?p1=$1 [L,QSA]
#www.example.com/parameter1/

页面.php

<?php
echo "Hello World";
//session_start();
//session_destroy();
?>

/测试/session_define.php

<?php
session_start();
$_SESSION["session_test"] = "123456789";
?>
<a href="session_write.php">session_write.php</a>

/测试/session_write.php

<?php
session_start();
echo "session_test:".$_SESSION["session_test"]."<br>";
?>

好的场景:

  1. 在 Google Chrome 中,我将 URL 命名为“domain”/test/session_define.php
  2. 我点击链接,进入“domain”/test/session_write.php 页面,看到列出了 SESSION 变量“1234578”。一切正常。

错误场景(在 page.php 中我取消注释“删除会话”):

  1. 在 Google Chrome 中,我将 URL 命名为“domain”/test/session_define.php
  2. 我单击该链接,它转到“domain”/test/session_write.php,但 $_SESSION[“session_test”] 未定义(由于 page.php 它被删除)。

我正在调用子文件夹中的特定 php 文件(URL),但我认为无法满足条件: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ page.php?p1=$1 [L,QSA]

我不明白当我直接调用 PHP 文件“/test/session_define.php”时,page.php 怎么会删除 SESSION。不应该使用 .htaccess 进行重写。在 page.php 中,我也故意声明了:echo "Hello World"; 但这并没有显示出来,只是删除了会话。

请问我做错了什么?我哪里做错了?非常感谢您的帮助。

.htaccess
  • 1 个回答
  • 32 Views
Martin Hope
Ayan Biswas
Asked: 2024-08-31 01:49:14 +0800 CST

如何使用 .htaccess 将包含问号和特定字符串的 URL 重定向到根域

  • 5

我网站的旧 URL 结构是这样的

https://www.naturablooms.com/wholesale-pricelist?color_id&flower_type_id&name_search_start&page=1&product_type=Dried&psearch&ship_service

我们的网站当前的 URL 结构已针对 SEO 进行了更改。现在我们必须将所有此类带有问号后 color_id 的 URL 重定向到根域。这就像

从

https://www.naturablooms.com/wholesale-pricelist?color_id&flower_type_id&name_search_start&page=1&product_type=Dried&psearch&ship_service

到

https://www.naturablooms.com/

我们在 .htaccess 中尝试了以下内容

RewriteEngine On
RewriteCond %{QUERY_STRING} ^color_id.*$
RewriteRule ^(.*)$ /$1? [R=301,L]

但它会重定向到 https://www.naturablooms.com/wholesale-pricelist 而不是根域 https://www.naturablooms.com/

我们需要将其重定向至https://www.naturablooms.com/

如果有人能帮助我弄清楚并解决这个问题,我将非常感激。

.htaccess
  • 1 个回答
  • 13 Views
Martin Hope
Andreas Ströbel
Asked: 2024-03-16 03:00:33 +0800 CST

htaccess RewriteRule:删除和替换

  • 6

我想通过 .htaccess 重定向,旧的 URL 就像

https://www.domain.de/something/?action=set_login&syncid=1&title=2&username=3&password=4&description=5&link=6&icon=7&localid=44285,3826274818&modified=2021-03-30%2014:06:59&seccode=8&valid=1

新的 URL 应类似于:

https://www.domain.de/something/set_login.php?syncid=1&title=2&username=3&password=4&description=5&link=6&icon=7&localid=44285,3826274818&modified=2021-03-30%2014:06:59&seccode=8&valid=1

所以,简而言之:

消除:?action=

使用动作文本作为脚本名称:set_login应该是脚本名称set_login.php

以下所有参数应以不变的方式附加。

有什么想法吗?我想它必须分为两条规则?

我尝试了这样的操作,但是之后仍然添加“某事”和操作参数set_login.php?,我必须手动实现每个脚本名称:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} .*action=get_logins.*
RewriteRule ^(.*) https://%{HTTP_HOST}/something/set_login.php?$1 [QSA,L]
</IfModule>
.htaccess
  • 1 个回答
  • 19 Views
Martin Hope
Greg
Asked: 2024-02-07 22:05:19 +0800 CST

RewriteRule 和 RedirectPermanent 冲突(添加查询字符串)

  • 6

我的所有RedirectPermanent规则都将查询字符串添加到 URL。该不需要的查询与重定向的粗略 URL 重新定义相匹配,RewriteRule如下所示:

RewriteRule ^page-([0-9]+)-(.*)$ index.php?page=page&id=$1 [L]

这条规则可以很好地创建这种 URL:

https://example.com/page-320-enfants

301重定向定义如下:

RedirectPermanent /page-320-enfants /page-2028-pour-les-invitees

问题:这会将查询字符串添加到新创建的 url 中:

https://example.com/page-2028-pour-les-invitees?page=page&id=320

我尝试使用RewriteRule(旧网址到新网址)而不是按照RedirectPermanent旧问题中的建议使用,但它具有完全相同的效果。

我错过了什么吗?

更新 :

正如所建议的,我尝试使用RewriteRule放置在通用规则本身之前:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Redirect Permanent #
RewriteRule ^page-2028-pour-les-invitees$ page-320-enfants [R=301,L]

# Common rules #
...
RewriteRule ^page-([0-9]+)-(.*)$ index.php?page=page&id=$1 [L]
...

此尝试根本不会触发。问题可能出在语法上吗?

.htaccess
  • 1 个回答
  • 29 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve