从页面的ID名称不工作htaccess的重写
我打电话?页=约
使用GET方法在index.php文件(关于是一种选择选项,也就是。)的形式。当我点击提交,该URL将是这样的:
I'm calling ?page=about
using the GET method in a form on index.php (ie. 'about' is a select option). Once I click submit, the URL will look like this:
http://example.com/?page=about
不过,我想它看起来像这样:
However I would like it to look like this instead:
http://example.com/about
但保留脚本(PHP)工作的index.php(千万不要,不希望有一个关于文件),IE浏览器。我想利用获取值的同一页上一次的形式发送。我可以让PHP脚本的工作,它的反应很好,但URL重写不会在所有的工作。
but keep the script (PHP) working on index.php (do don't and don't want to have an 'about' file), ie. I would like to make use of the GET values on the same page once the form is sent. I can make the php script work, it reacts fine, but the URL rewriting does not work at all.
我曾尝试以下htaccess的重写,但它不会做任何事情,网址如上依然存在。
I have tried the following htaccess rewrite, but it doesn't do anything, the URL remains as above.
我的htaccess的:
My htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?page=$1 [L,QSA]
我将不胜AP preciate你们的帮助,因为我不知道为什么,这是行不通的。我已经通过网络搜索,每个人都指出了这条规则,但它只是没有做任何事情都对我。
I would greatly appreciate your help, as I have no idea why this isn't working. I have searched through the net, and everyone points to this rule, yet it just doesn't do any thing at all for me.
感谢很多提前!
编辑:
让我发表我的PHP code我用的,对不起,我错过了。我已删除了动作
属性现在是我使用它,我知道提交表单时,送我去同一个浏览器:
Let me post my php code I use, sorry, I missed that. I have removed the action
attribute for now as I'm using it in a browser that I know is sending me to the same when submitting the form:
<?php
$page = $_GET['page'];
switch($page){
case 'about': echo 'I am me'; break;
case 'galery': echo 'Nice pictures here'; break;
}
?>
<body>
<form action="/" method="get">
<select name="page">
<option value="about">about</option>
<option value="galery">galery</option>
</select>
<input type="submit" value="Submit" />
</form>
</body>
编辑#2:
我不得不添加行动=/
的形式标记,以便anubhava的解决方案工作。
I had to add action="/"
to the form tag in order anubhava's solution to work.
这应该是你的完整的.htaccess:
This should be your complete .htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
#external redirect from /?page=about OR /index.php?page=about to /about
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:index\.php|)\?page=([^\s]+) [NC]
RewriteRule ^ /%1? [R=301,L]
#internal forward from /about to /?page=about
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+?)/?$ /?page=$1 [L,QSA]