简体   繁体   English

.htaccess mod_rewrite无法捕获整个URL

[英].htaccess mod_rewrite not catching entire URL

htaccess file htaccess文件

RewriteEngine On
RewriteRule ^(.+)$ index.php?url=$1 [PT,L]

Whatever I add to the URL mod_rewrite catches it and puts in it the GET variable url and redirects the user in the background to my index.php page. 无论我添加到URL的什么内容,mod_rewrite都将其捕获,并将GET变量url放入其中,并将用户在后台重定向到我的index.php页面。

Example: 例:

http://www.mysite.com/members/profile

In my index.php page if I then output the url parameter to the screen I get 在我的index.php页面中,如果我随后将url参数输出到屏幕上,

members/profile

That is what I want but the problem is when I add something like this to the URL: 那就是我想要的,但是问题是当我向URL添加如下内容时:

members/profile##

OR 要么

members/profile...

and probably loads of other special characters mod_rewrite only seems to catch the: 并且可能加载的其他特殊字符mod_rewrite似乎只能捕获:

members/profile

leaving out the characters at the end for some reason. 由于某种原因在结尾处省略字符。

I don't want that as I need catch every single chacter in the URL. 我不需要,因为我需要捕获URL中的每个字符。 Does anyone know why it is not catching the whole URL? 有谁知道为什么它不能捕获整个URL? Thanks. 谢谢。

I tested your code with a .htaccess file containing the following: 我使用包含以下内容的.htaccess文件测试了您的代码:

RewriteEngine On
RewriteRule ^(.+)$ index.php?url=$1 [PT,L]

and this php script called index.php : 而这个php脚本叫做index.php

<?php
echo '$_GET[\'url\'] = "' . $_GET['url'] . '"';
?>

Indeed, it didn't work. 确实,它没有用。 But nothing worked, not even the things you described that did. 但是没有任何效果,甚至您描述的功能也没有效果。 So why would that be case? 那么为什么会这样呢? Well, Apache doesn't pass GET parameters to the script unless you add a flag: QSA . 好吧,除非您添加标志: QSA,否则Apache不会将GET参数传递给脚本。 So your code will work if you change your .htaccess file to: 因此,如果将.htaccess文件更改为:

RewriteEngine On
RewriteRule ^(.+)$ index.php?url=$1 [PT,L,QSA]

One issue you had was that hashtags weren't passes to the PHP script. 您遇到的一个问题是,标签没有传递给PHP脚本。 Unfortunately, that is something you can't solve. 不幸的是,这是您无法解决的。 The reason for this is that every character starting at the first hash isn't passed to the webserver by the browser. 这样做的原因是,从第一个哈希开始的每个字符都不会被浏览器传递到Web服务器。 So you will never be able to get those characters, unless you resort to some fancy JavaScript. 因此,除非您使用一些精美的JavaScript,否则您将永远无法获得这些字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM