我如何使用htaccess的网址删除一个变量名? [英] How do I remove a variable name from a URL using htaccess?

查看:140
本文介绍了我如何使用htaccess的网址删除一个变量名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我希望用户能去我的网站的一些网址像 / 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]

这篇关于我如何使用htaccess的网址删除一个变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆