Kevin
Kevin

Reputation: 51

mod rewrite with $_get works but not for subfolders

What I got working now is this:

 webshop/index.php?page=home

rewritten to:

webshop/home

But now I want to have the following link:

webshop/account/login

I thought that it should work with the code that i got but it doesn't.

What I got is the following PHP code:

<?php
if (isset($_GET['page'])) { 
$page = $_GET['page'];      
} else {                    
   $page = 'home';      
}
if (strpos($page, '/') !== false || !file_exists("pages/$page.php")) {  
     $page = 'error';                                               
}
include ("pages/$page.php");        
?>

and this is my .htaccess file:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^webshop/([^/]*)$ /webshop/?page=$1 [L]

Upvotes: 1

Views: 23

Answers (1)

Shayan
Shayan

Reputation: 966

try this, you can return multi params

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteBase /webshop/

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  ^/([^/]+)/?([^/]*)?   [NC]
RewriteRule .*    index.php?page=%1&route=%2  [L]

Upvotes: 1

Related Questions