0

我想问一个关于.htaccess. 我有一个来自 的表单index.html,并且想将一个值传递给receiver.php。你如何配置.htaccess输出http://localhost/demo/receiver/jibberish而不是http://localhost/demo/receiver.php?fid=jibberish

http://{host_name}/demo/index.html

<form method="get" action="receiver.php">
  FID <input type="text" name="fid" value="jibberish"> <br>
  <input type="submit" value="Submit"> 
</form>

http://{host_name}/demo/receiver.php

<?php 
  echo $_GET['fid'];
?>

我很难过。这是我的.htaccess代码。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/$1 -f
RewriteRule ^/receiver.php$ /receiver.php?fid=$1 [PT]
</IfModule>
4

2 回答 2

2

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(receiver)\.php\?fid=([^\s]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(receiver)/(.+?)/?$ /$1.php?fid=$2 [L,NC,QSA]

确认它工作正常后,替换R=302R=301. R=301在测试你的 mod_rewrite 规则时避免使用(永久重定向)。

于 2013-05-29T03:49:56.570 回答
1

这应该在根目录的一个 .htaccess 文件中工作:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} /demo/receiver.php\?fid=([^&\s]+) [NC]
RewriteRule  .*            /demo/receiver/%1?  [R=301,L,NC]

RewriteCond %{REQUEST_URI}  !receiver\.php [NC]
RewriteRule  ^demo/receiver/([^/]+)/?  /demo/receiver.php?fid=$1 [L,NC]
于 2013-05-29T03:55:02.900 回答