在我发布此问题之前,我已经在SO和Google中进行了搜索,最重要的是我还使用了mod_rewrite generator。
然而,我把它放在我的.htaccess中的结果似乎没有起作用。
我当前的网址:
http://localhost/jeff/test/result.php?start=2-1-2014&end=2-1-2014&submit=Go
我想要的输出:
http://localhost/start/2-1-2014/end/2-1-2014
我从mod_rewrite生成器获得的代码:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+/jeff/test/result\.php\?start=([^&]+)&end=([^&\s]+) [NC]
RewriteRule ^ /start/%1/end/%2? [R=302,L]
RewriteRule ^start/([^/]+)/end/([^/]+)/?$ /jeff/test/result.php?start=$1&end=$2&submit=Go [L,QSA]
现在每次按下提交按钮,它仍然会将我返回到旧网址,而不是根据.htaccess重写网址
旁注:
我哪里出错了?我相信发电机能给我正确的结果。
这是我的提交表单代码:
<form method="get" action="result.php">
From: <input type="text" name="start" /><br />
End: <input type="text" name="end" /><br />
<input type="submit" value="Go" />
</form>
和我的result.php代码:
error_reporting(E_ALL); ini_set('display_errors', 1);
// bind column to variable
//Connect to DB
$host = "localhost"; //Host Name
$port = '3306'; //Default MySQL Port
$dbname = "mama"; //Database Name
$db_username = "root"; //MySQL Username
$db_password = ""; //MySQL Password
$dsn = "mysql:host=$host;port=$port;dbname=$dbname"; //Data Source Name = Mysql
$db = new PDO($dsn, $db_username, $db_password); //Connect to DB
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$start_date = $_GET['start'];
$end_date = $_GET['end'];
$start = DateTime::createFromFormat('d-m-Y', $start_date);
$end = DateTime::createFromFormat('d-m-Y', $end_date);
$query = $db->prepare("SELECT * FROM log WHERE log_datetime >= :start AND log_datetime < :end + INTERVAL 1 DAY");
$success = $query->execute(array(':start'=>$start->format('Y-m-d'), ':end'=>$end->format('Y-m-d')));
}
// Catch any exception thrown
catch (PDOException $e) {
echo "Error: " . $e->getMessage();
// Exit, redirect, whatever you need to do.
}
$rows = $query->fetchAll(PDO::FETCH_OBJ);
我当前设置的屏幕截图:
答案 0 :(得分:0)
没有RewriteBase
错误,不适合你。
将此代码放入 DOCUMENT_ROOT/.htaccess
文件:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+/jeff/test/result\.php\?start=([^&]+)&end=([^&\s]+) [NC]
RewriteRule ^ /start/%1/end/%2? [R=302,L]
RewriteRule ^start/([^/]+)/end/([^/]+)/?$ /jeff/test/result.php?start=$1&end=$2&submit=Go [L,QSA]