Go 中是否有一种直接的方法来修改 URL/URI,而无需使用正则表达式来提取组件(即我正在寻找一种确定性的“经过验证的”方式/方法)。
例如,我有两种类型的 URL 发送到我的应用程序:
http://wiley.coyote.acme.co/this/is/a/long/path?param1=123¶m2=456https://road.runner.acme.co/another/long/path?meep=meep我需要做的是重写 URL,以便参数列表和端点/路径完好无损,但协议从 更改为http到https(除非它已经是https),并且整个主机名/FQDN 需要更改为egghead.local。例如,上面的两个 URL 将变为:
https://egghead.local/this/is/a/long/path?param1=123¶m2=456https://egghead.local/another/long/path?meep=meep是否有可靠/成熟的方法来处理这个问题(例如最好没有正则表达式)?
我正在尝试编写一个正则表达式,将包含大写字符的 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 文件中实现此重定向规则
您好,我面临从网址中删除 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) 我正在使用 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) 以下是我的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的内容重写。
然而,我最终得到“本地主机重定向你太多次”。
有什么想法导致错误吗?
我的客户端要求我用PHP创建一个Web应用程序,最后我使用了Symfony.在交付时,他告诉我他已经发布了一个带有嵌入式Web视图的软件,该软件指向硬编码的URL:
www.domain.com/dir/tools.php
现在他希望Web应用程序出现在它的Web View中,但该软件被大约400个客户使用,我们不能指望更改硬编码的URL.
您认为我怎么能干净利落地做到这一点:
我已经创建了一个PHP分页系统,但我想隐藏地址栏中的_GET变量.
目前我的看起来像这样: http://example.com/images.php?page=1
但我见过一些网站http://example.com/images/1/.
只是想知道他们是怎么回事?谁能指出我正确的方向?干杯
嗨:在我的网站上,我发现他们的网址非常简单:
http://example.com/questions/4486620/randomaccessfile-probelm
通常网址应该像:
http://example.com/questions?xx=4486620&title=randomaccessfile-probelm
也就是说,url中没有"&"组合的请求参数.
他们是怎么做到的?有框架吗?
更新: 我的应用程序在tomcat下运行.
我已经在cakePHP中开发了一个庞大的管理面板,我可以使用SITE_URL/admin进行访问.现在我想通过SITE_URL/jpaneladmin更改此URL而不更改我使用admin_前缀定义的任何功能.有任何想法吗)?
我可以通过任何路由规则来更改此网址?
我正在努力使网址重写,我想删除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服务器日志也没有错误.
我应该在项目中重写所有网址吗?