标签: url-rewriting

在 Go 中替换 URL 中的协议和主机名

Go 中是否有一种直接的方法来修改 URL/URI,而无需使用正则表达式来提取组件(即我正在寻找一种确定性的“经过验证的”方式/方法)。

例如,我有两种类型的 URL 发送到我的应用程序:

  • http://wiley.coyote.acme.co/this/is/a/long/path?param1=123&param2=456
  • https://road.runner.acme.co/another/long/path?meep=meep

我需要做的是重写 URL,以便参数列表和端点/路径完好无损,但协议从 更改为httphttps(除非它已经是https),并且整个主机名/FQDN 需要更改为egghead.local。例如,上面的两个 URL 将变为:

  • https://egghead.local/this/is/a/long/path?param1=123&param2=456
  • https://egghead.local/another/long/path?meep=meep

是否有可靠/成熟的方法来处理这个问题(例如最好没有正则表达式)?

string url substring url-rewriting go

1
推荐指数
1
解决办法
3653
查看次数

如何在 .htaccess 中将 URL 从大写重写为小写

我正在尝试编写一个正则表达式,将包含大写字符的 URL 重写为相同的 URL,但全部为小写。

例子:

example.com/foO-BAR-bAz重写为example.com/foo-bar-baz

example.com/FOO-BAR-BAZ重写为example.com/foo-bar-baz

example.com/foo-bar-baz 不匹配

我尝试^\/(?=.*[A-Z])将字符串与至少一个大写字符匹配,但它与完整字符串不匹配。我也知道我需要使用“捕获组”,但我不确定如何使用。

我将在 Apache 服务器的 .htaccess 文件中实现此重定向规则

regex apache .htaccess mod-rewrite url-rewriting

1
推荐指数
1
解决办法
1628
查看次数

从 url 中删除/重定向 public/index.php 以防止重复的 url

您好,我面临从网址中删除 public/index.php 的问题。从 url 中删除/重定向 index.php 以防止重复的 url 此链接确实帮助我删除了 index.php 表单 url,但我无法从 url 中删除 public/index.php。这是我的下面的 htacces 代码

 RewriteEngine On
 #REmove index.php from url starts
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php[^/] /$1? [L,R=302,NC,NE]

    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2? [L,R=302,NC,NE]
 #Remove index.php from url ends

   RewriteCond %{HTTPS} off
   RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

   RewriteCond %{HTTP_HOST} !^www\. [NC]
   RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

 <IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$    public/    [L]
   RewriteRule    (.*) public/$1    [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

但是当我添加下面的代码来删除 htaccess 中的 public/index.php 时,它不起作用:-

RewriteCond …
Run Code Online (Sandbox Code Playgroud)

apache .htaccess mod-rewrite url-rewriting laravel

1
推荐指数
1
解决办法
643
查看次数

重定向 URL 中的第二个尾部斜杠

我正在使用 URL 重写来强制 http 到 https 重定向。它正在工作,只是它在 URL 中添加了第二个尾部斜杠。例如,如果我访问http://example.com,重写的 URL 最终会是https://example.com//。我什至不想要 1 个尾部斜杠,更不用说 2 个,而且我无法摆脱它。我尝试了这个解决方案,但没有成功。可能是因为这个人想去掉结尾的斜杠,而我有两个斜杠,所以它不匹配?

我的 web.config 文件中有以下规则。我正在运行带有 IIS 10 和 URL 重写模块的 Windows Server 2019。如果有人能告诉我哪里出错了,我将不胜感激!

<rule name="HTTPS Redirect" stopProcessing="true">
    <match url="(.*)" />
        <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
        </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{REQUEST_URI}" appendQueryString="false" />
</rule>
<rule name="SEO - Remove trailing slash" stopProcessing="false">
    <match url="(.+)/$" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTP_METHOD}" pattern="GET" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        </conditions>
    <action …
Run Code Online (Sandbox Code Playgroud)

iis url-rewriting iis-10

1
推荐指数
1
解决办法
3036
查看次数

NextJs 重写产生 localhost redirected you too much times 错误

以下是我的next.config.js:

// next.config.js

module.exports = {
  async rewrites() {
    return [
      {
        source: '/results',
        destination: 'https://mywebsite.com/results',
      },
    ];
  },
};
Run Code Online (Sandbox Code Playgroud)

根据 Nextjs 重写文档(https://nextjs.org/docs/api-reference/next.config.js/rewrites#rewriting-to-an-external-url),访问 https://nextjswebsite.com/results,页面内容应使用https://mywebsite.com/results的内容重写。

然而,我最终得到“本地主机重定向你太多次”。

有什么想法导致错误吗?

javascript backend url-rewriting next.js

1
推荐指数
1
解决办法
5459
查看次数

如何以干净的方式将请求重定向到不存在的PHP文件到现有的DIR?

我的客户端要求我用PHP创建一个Web应用程序,最后我使用了Symfony.在交付时,他告诉我他已经发布了一个带有嵌入式Web视图的软件,该软件指向硬编码的URL:

www.domain.com/dir/tools.php

现在他希望Web应用程序出现在它的Web View中,但该软件被大约400个客户使用,我们不能指望更改硬编码的URL.

您认为我怎么能干净利落地做到这一点:

  • 创建www.domain.com/dir/tools.php并使用重定向?哪一个怎么样?
  • 使用URL重写?任何片段表示赞赏,我不知道如何做到这一点.

php redirect url-rewriting

0
推荐指数
1
解决办法
204
查看次数

隐藏地址栏中的文件

我已经创建了一个PHP分页系统,但我想隐藏地址栏中的_GET变量.

目前我的看起来像这样: http://example.com/images.php?page=1

但我见过一些网站http://example.com/images/1/.

只是想知道他们是怎么回事?谁能指出我正确的方向?干杯

url-rewriting

0
推荐指数
1
解决办法
1038
查看次数

如何简化网址

嗨:在我的网站上,我发现他们的网址非常简单:

http://example.com/questions/4486620/randomaccessfile-probelm

通常网址应该像:

http://example.com/questions?xx=4486620&title=randomaccessfile-probelm

也就是说,url中没有"&"组合的请求参数.

他们是怎么做到的?有框架吗?

更新: 我的应用程序在tomcat下运行.

url url-rewriting

0
推荐指数
1
解决办法
2160
查看次数

Cakephp更改管理员前缀

我已经在cakePHP中开发了一个庞大的管理面板,我可以使用SITE_URL/admin进行访问.现在我想通过SITE_URL/jpaneladmin更改此URL而不更改我使用admin_前缀定义的任何功能.有任何想法吗)?

我可以通过任何路由规则来更改此网址?

.htaccess routes cakephp url-rewriting cakephp-1.3

0
推荐指数
1
解决办法
491
查看次数

Yii url重写删除index.php

我正在努力使网址重写,我想删除index.php,我已经做了一些研究,并找到了在线文档.

这是我到目前为止所做的,我取消了我的main.php urlmaneger,我有以下内容

'urlManager'=>array(
            'urlFormat'=>'path',
            'showScripName'=>false,
            'rules'=>array(
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ),
        ),
Run Code Online (Sandbox Code Playgroud)

我有.htaccess,它在我的yiiApplication中被激活了

RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
Run Code Online (Sandbox Code Playgroud)

现在,当我启动应用程序时,它给了我以下错误.

**Property "CUrlManager.showScripName" is not defined.**
Run Code Online (Sandbox Code Playgroud)

我如何解决这个问题?我确实打开了我的Rewrite引擎,并且我的php日志或wamp服务器日志也没有错误.

我应该在项目中重写所有网址吗?

php .htaccess mod-rewrite url-rewriting yii

0
推荐指数
1
解决办法
271
查看次数