简体   繁体   中英

Url Rewrite Using htaccess not working

I am using this php code in file qas.php

<?php
include 'config.php';
include 'head.php';
$qid = $_GET['qid'];
if(isset($_SESSION['username'])){
$myid = $_SESSION['userid'];
$time = time();
if(isset($_POST['submit'])){
$ans = $_POST['ans'];
mysql_query("insert into qas (aid,qid,uid,answer,time) values ('','$qid','$myid','$ans','$time')");
echo "<div class='menua'>Answer Posted..!!</div><br/>";
}
?>

and .htaccess code

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+) $ qas.php?qid=$1
RewriteRule ^([a-zA-Z0-9_-]+) /$ qas.php?qid=$1

but nothing works it says error

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.Please contact the server administrator at admin@example.com to inform them of the time this error occurred, and the actions you performed just before this error.More information about this error may be available in the server error log.

Remove the space before the $ and /$, so your rules are just like this:

RewriteRule ^([a-zA-Z0-9_-]+)$ qas.php?qid=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ qas.php?qid=$1

Also, your PHP is invalid - you've got an opening brace on the first if but no closing one. Put a closing } on a new line just after $time = time();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM