php - htaccess mod_rewrite does not work + is it possible? -


i've been trying past hour rewrite following url using mod_rewrite in htaccess. original url http://localhost/index.php?part=main&page=download desired url http://localhost/index.php?part=/main/download

i remember past htaccess didn't work on on pc reason.. platform: windows 7 ultimate 64bit. software: apache - xampp.

i checked httpd.conf , couldn't find wrong it,it set "allowoverride all"... idea what's problem might be? , possible rewrite way mentioned above (file.php?part=/$1/$2 instead of file.php?part=$1&page=$2)?

thank time, appreciate it!

pasted following code in htaccess , has returned error 500

options +followsymlinks rewriteengine on rewriterule ^index.php?part=main&page=download (.*)$ http://localhost/index.php?part=/main/download$1 [r=301,nc] 

if can done in php, please explain how. contents of index.php:

<?php  session_start(); # disable notices  if(!file_exists('assets/config/install/installdone.txt')){     header("location: assets/config/install/install.php");     exit; } else {     # database information     require_once("assets/config/database.php");      require_once("assets/config/properties.php");     require_once("assets/config/afuncs.php");     # define $getbase variable     $getbase = isset($_get['part']) ? $_get['part'] : "";      switch($getbase){         case null:             header('location: ?part=main');             break;         case "main":             $getslug = $mysqli->query("select slug ".$prefix."pages");             while($fetchslug = $getslug->fetch_assoc()) {                 $slugarray[] = $fetchslug['slug'];             }             include("sources/structure/header.php");             include("sources/structure/theme/left.php");             include("sources/structure/theme/right.php");             include("sources/public/main.php");             include("sources/structure/footer.php");             break;         case "ucp":             include("sources/structure/header.php");             include("sources/ucp/main.php");             include("sources/structure/footer.php");             break;         case "admin":             include("sources/structure/admin/header.php");             include("sources/admin/main.php");             break;         case "gmcp":             include("sources/structure/header.php");             include("sources/gmcp/main.php");             include("sources/structure/footer.php");             break;         case "misc":             include("sources/misc/main.php");             break;         default:             include("sources/structure/header.php");             include("sources/public/main.php");             include("sources/structure/footer.php");             break;     } }  $mysqli->close(); ?> 

you can re-write in whatever url style wish, has regex in can pretty anything.

drop rule in .htaccess file

options +followsymlinks rewriteengine on rewriterule ^index.php?part=main&page=download (.*)$ http://localhost/index.php?part=/main/download$1 [r=301,nc] 

in addition, set:

  <directory ...>    allowoverride none 

to

<directory ...>  allowoverride 

if it's opposite settings in .htaccess file have no effect, it'll settings in httpd.conf file.

if don't want .htaccess involved or having difficulties can insert rule directly virtualhost example:

<virtualhost *>   servername www.example.com   rewriteengine on   rewriterule ^index.php?part=main&page=download (.*)$ http://localhost/index.php?part=/main/download$1 [r=301,nc] </virtualhost> 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -