mod_rewrite [PT] 标志返回错误请求
最初,编写此代码是为了创建“漂亮” url。
当使用下面的代码时,mod_rewrite 会正常工作。
<Directory /var/www/vhosts/myurl.com/httpdocs>
Options Indexes FollowSymLinks
php_admin_flag engine on
php_admin_value open_basedir none
AllowOverride all
Order allow,deny
Allow from all
</Directory>
RewriteEngine on
RewriteCond %{HTTPS} !=off
RewriteCond %{LA-U:REQUEST_FILENAME} !-f
RewriteCond %{LA-U:REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond $1 ^(register|account|logout|profile|edit_profile).*$
RewriteRule ^/(.*)$ https://myurl.com/?get=$1
它采用任何匹配的 URL,例如 https://myurl.com/register 并将其重写为 https://myurl.com/?get=register。找到适当的页面并显示在浏览器中。
但是,我希望将原始网址传递到浏览器。为了实现这一点,我将 [PT] Flag 添加到我的 RewriteRule 中,如下所示:
RewriteRule ^/(.*)$ https://myurl.com/?get=$1 [PT]
这让 https://myurl.com/register (与上面相同的 url)通过到浏览器,但不再显示该页面。相反,它返回以下错误:
Bad Request
Your browser sent a request that this server could not understand.
Client sent malformed Host header
相关信息:
操作系统: Linux
服务器: Apache
控制: Plesk
目录: /var/www/vhosts/myurl.com/conf
文件: vhost_ssl.conf
我搜索了多个论坛和文章,但没有结果。
第 1 条: 使用 mod_rewrite 制作更漂亮的 URL(包括使用[PT] Flag)
有谁对这里发生的事情以及如何解决它有想法吗?如何获取要显示的“pretty” url?
Initially, this code was written to create "pretty" urls.
When using the code below, mod_rewrite works as it should.
<Directory /var/www/vhosts/myurl.com/httpdocs>
Options Indexes FollowSymLinks
php_admin_flag engine on
php_admin_value open_basedir none
AllowOverride all
Order allow,deny
Allow from all
</Directory>
RewriteEngine on
RewriteCond %{HTTPS} !=off
RewriteCond %{LA-U:REQUEST_FILENAME} !-f
RewriteCond %{LA-U:REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond $1 ^(register|account|logout|profile|edit_profile).*$
RewriteRule ^/(.*)$ https://myurl.com/?get=$1
It takes any matching url such as https://myurl.com/register and rewrites it as https://myurl.com/?get=register. The appropriate page is found and displayed in the browser.
However, I want the original url to be passed through to the browser. To achieve this, I added the [PT] Flag to my RewriteRule as shown below:
RewriteRule ^/(.*)$ https://myurl.com/?get=$1 [PT]
This lets https://myurl.com/register (same url as above) through to the browser but no longer displays the page. Instead, it returns the following error:
Bad Request
Your browser sent a request that this server could not understand.
Client sent malformed Host header
Relevant Info:
OS: Linux
Server: Apache
Control: Plesk
Directory: /var/www/vhosts/myurl.com/conf
File: vhost_ssl.conf
I've searched multiple forums and articles to no avail.
Article 1: Making prettier URLs with mod_rewrite (includes use of [PT] Flag)
Does anyone have ideas on what's going on here and how to fix it? How can I get the "pretty" url to display?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
于是经过两天的折腾,终于解决了这个难题。
首先,我尝试了 RewriteRule,将其从: 更改
为
不带任何标志。
每当触发重写时,就会产生无限循环。但我注意到循环是在没有重定向 url 的情况下发生的(维护 'pretty url')。进步!
我决定简化代码。我从 RewriteCond 中删除了 'LA-U:' ,如下所示:
就
这样!感谢那些发表评论的人。希望这对将来的人有帮助。
So after two days of frustration, I finally solved the puzzle.
First I experimented with the RewriteRule from by changing it from:
to
without any flags.
This produced an infinite loop whenever the rewrite was triggered. But I noticed that the loop was happening without redirecting the url (maintaining the 'pretty url'). Progress!
I decided to simplify the code. I removed 'LA-U:' from the RewriteCond as shown below:
to
That did the trick! Thanks to those that commented. Hope this helps someone in the future.