我如何使用htaccess的网址删除一个变量名?如何使用、变量名、网址、htaccess

2023-09-02 01:11:15 作者:正儿八经的小骚年°

所以基本上我希望用户能去我的网站的一些网址像 / 45678 ,而不必使用 / ?p = 45678 ,所以我真的只是想删除的变量名。我已经使用mod_rewrite尝​​试过,但似乎只是除去名字的时候,网页被访问。

下面是当前code:

  RewriteEngine叙述上

的RewriteCond%{QUERY_STRING} ^ P =([0-9] + = $

重写规则^ / $ /%1 [R]
 

解决方案

简单地改变所有链接到/ 45678,而不是P = 45678。还是我完全误解你?因为我从您的文章得到的是它正常工作,除非你手动访问?p = 45678在那里,因为它保持为P = 45678。

编辑: 这是我使用的 http://www.madphp.org/dev/ 什么,给它一去,就像我的一个魅力(这也消除了index.php的一部分)。要访问您现在更清洁的网址,你会简单地爆炸了 $ _ SERVER ['PATH_INFO'] 变量获得所有必需的参数,你的PHP脚本中。

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php / $ 1 [L]
 
这个网址怎么删啊,高手来,这不是一般的强啊

So basically I want users to be able to go to my website with a URL of something like /45678, instead of having to use /?p=45678, so really I just want to remove the variable name. I've tried using mod_rewrite, but it seems that is only for removing the name when the page is visited.

Here is the current code:

RewriteEngine On 

RewriteCond %{QUERY_STRING} ^p=([0-9]+=$

RewriteRule ^/$ /%1 [R]

解决方案

Simply change all of your links to /45678 rather than ?p=45678. Or did I misunderstand you completely? Because what I got from your post is that it works properly, unless you manually access the ?p=45678 where as it stays as ?p=45678.

EDIT: This is what I am using for http://www.madphp.org/dev/, give it a go, works like a charm for me (it also removes the index.php part). To access your now cleaner URL you would simply explode the $_SERVER['PATH_INFO'] variable to get all of the required parameters within your PHP script.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]