htaccess的重写规则,去掉问号 [英] htaccess rewrite rule, remove question mark
问题描述
让我们说我有以下网址:
我应该如何从URL,EI删除问号重写
要这样的:
http://example.com/index.php?param
下面是我的code,不工作:
RewriteEngine叙述上
重写规则^(。*)$ /index.php?$1 [P]
两个完全不同的事情需要发生。首先,你需要外部重定向浏览器显示的东西在URL地址栏不同。第二,当浏览器的重发的所述第二请求,服务器内部重写查询字符串后面。在URL可以不要随意添加或删除的东西在野外,因为它们的定位器的。您可以创建一个新的定位器,告诉浏览器使用这个新的代替旧的,然后在内部服务器上改变新一回旧的。
请参见这个答案的顶部一个解释
使浏览器转到新的URL:
RewriteEngine叙述上
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,9} \ /(index\.php)\(?[^&放大器; \] +)
重写规则^ /%1? [L,R = 301]
这需要对URL的请求: http://example.com/?something 并重定向浏览器的网址: http://example.com/something
然后,你需要在内部改写回:
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$ /index.php?$1 [L]
在提出要求的 http://example.com/something ,服务器重写的URI /index.php?something
。这是内部的服务器,以便浏览器对此一无所知,并会继续显示URL http://example.com/something 而服务器处理的URI /index.php?something
。
Let's say I have the following url:
how should I remove question mark from the url, e.i. rewrite
to something like this:
http://example.com/index.php?param
Here is my code, that doesn't work:
RewriteEngine On
RewriteRule ^(.*)$ /index.php?$1 [P]
Two completely different things need to happen. First you need to externally redirect the browser to show something different in the URL address bar. Second when the browser resends the 2nd request, the server internally rewrites the query string back. You can't arbitrarily add or remove things in URLs in the wild, as they are locators. You can create a new locator, tell the browser to use this new one instead of the old one, then internally on the server change the new one back to the old one.
See the top part of this answer for an explanation
To make the browser go to the new URL:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?([^&\ ]+)
RewriteRule ^ /%1? [L,R=301]
This takes a request for the URL: http://example.com/?something and redirects the browser to the URL: http://example.com/something
Then you need to internally rewrite it back:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]
When the request is made for http://example.com/something, the server rewrites the URI to /index.php?something
. This is internal to the server so the browser knows nothing about it and will continue to display the URL http://example.com/something while the server processes the URI /index.php?something
.
这篇关于htaccess的重写规则,去掉问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!