TechnoPulseLabs
TechnoPulseLabs

Reputation: 111

Multiple URL rewrites with .htaccess

I have below code in my .htaccess file, located in "root/mosaicin/" directory.,

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /mosaicin/

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(download-sample-papers|album|results|testimonials)/([^/]+)/?$ /$1.php?url=$2 [NC,QSA,L]

I want to rewrite my url www.domain.com/mosaicin/album.php/NID/ to domain.com/mosaicin/album/NID/ Same for other pages listed in rule (results,testimonials etc.)

Sample code in my album.php file is like

<?php
$cid = NULL;
$url = new SimpleUrl('/mosaicin/');
if($url->segment(2) == FALSE)
    $cname = 'NID';
else
    $cname = $url->segment(2);
$cname = urldecode($cname);
$ccsql = "SELECT courseid,cname FROM courses WHERE cname='".$cname."'";
$csql = $obj->select($ccsql);
if(count($csql)>0)
$cid = $csql[0]['courseid'];
?>

After getting courseid my code works to list items related to particular course. Currently when I go to page tplabs.in/mosaicin/album.php/NID everything works fine, but with link below tplabs.in/mosaicin/album/NID it gives 404 error.

Please help, Thanks in advance.

Upvotes: 0

Views: 895

Answers (1)

anubhava
anubhava

Reputation: 784898

Try these rules in your DOCUMENT_ROOT/.htaccess file:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /mosaicin/

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(download-sample-papers|album|results|testimonials)/([^/]+)/?$ $1.php?url=$2 [NC,QSA,L]

Upvotes: 2

Related Questions