Neeraz Poudel
Neeraz Poudel

Reputation: 13

My htaccess is not working properly

Here is my .htaccess content:

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /mtd/index.php?page=$1 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /mtd/index.php?page=$1&destination=$2&package=$3 [L]

The following link works correctly:

http://localhost/mtd/our-company.html [Rewrite Rule 1]

The page successfully passes the $_GET values index.php?page=page-name

Yet, the following link is Showing 404 Error

http://localhost/mtd/tours/nepal/index.html [Rewrite Rule 2]

This URL should pass $_GET values like:

index.php?page=tours&destination=nepal&package=index

This was working on Windows 8.1 with XAMPP Server and Remote Server with cPanel, but after I shifted to Ubuntu (Latest) with LAMP Stack, it is no longer working.

after executing command ls -al

    root@Neeraz:/var/www/mtd# ls -al
    total 1740
    drwxr-xr-x 15 neeraz root     4096 Jan 28 13:54 .
    drwxrwxrwx 70 root   root     4096 Jan 30 14:40 ..
    drwxrwxrwx 10 root   root     4096 Dec 17 15:56 admin
    -rwxrwxrwx  1 root   root    15992 Oct 23 12:25 ahome.html
    -rwxrwxrwx  1 root   root     3226 Nov 24 14:23 booknow.php
    drwxrwxrwx  3 root   root     4096 Jan  6 22:45 css
    -rwxrwxrwx  1 root   root   621280 Aug 15 15:56 delight-mockup.jpg
    -rwxrwxrwx  1 root   root     2531 Dec 10 17:47 find.php
    -rwxrwxrwx  1 root   root     1544 Nov 24 15:20 HandleTour.php
    -rwxrwxrwx  1 root   root      346 Feb  3 10:28 .htaccess
    drwxrwxrwx  3 root   root     4096 Jan  5 15:54 images
    drwxrwxrwx  2 root   root     4096 Oct 24 18:59 img
    -rwxrwxrwx  1 root   root    12098 Dec 16 14:00 index1.php
    -rwxrwxrwx  1 root   root    12372 Jan 29 06:20 index.php
    drwxrwxrwx  2 root   root     4096 Dec 23 15:15 jquery
    drwxrwxrwx  3 root   root     4096 Jan 28 13:58 Libs
    -rwxrwxrwx  1 root   root    13156 Jan 28 14:13 MainPage.php
    -rwxrwxrwx  1 root   root     1211 Jan  5 22:29 menu0.php
    -rw-rw-r--  1 neeraz neeraz    642 Jan 28 13:57 menulayout.php
    -rwxrwxrwx  1 root   root   476327 Aug 16 16:08 mt-delight1.jpg
    -rwxrwxrwx  1 root   root   474429 Aug 16 16:07 mt-delight.jpg
    drwxrwxr-x  3 neeraz neeraz   4096 Jan 28 11:35 nbproject
    -rwxrwxrwx  1 root   root     9892 Sep 19 10:46 nepal.html
    drwxrwxrwx  2 root   root     4096 Jan  7 00:27 _notes
    -rwxrwxrwx  1 root   root      684 Oct 25 09:00 PagesLoader.php
    -rwxrwxrwx  1 root   root     1189 Nov 21 00:00 pie.php
    drwxrwxrwx  2 root   root     4096 Oct 29 18:16 SpryAssets
    -rwxrwxrwx  1 root   root       45 Dec 17 16:02 test.php
    drwxrwxrwx  2 root   root     4096 Dec 29 14:19 TourGallery
    -rwxrwxrwx  1 root   root     9266 Sep  5 13:29 tour.html
    -rwxrwxrwx  1 root   root    18333 Jan  5 14:05 tours.php
    drwxrwxrwx  2 root   root     4096 Oct 27 16:18 TrekkingMap
    drwxrwxrwx  3 root   root     4096 Dec 29 14:19 uploaded
    drwxrwxrwx  2 root   root     4096 Dec 15 19:39 uploads
    root@Neeraz:/var/www/mtd# 

Upvotes: 1

Views: 333

Answers (1)

anubhava
anubhava

Reputation: 786289

You need correct RewriteBase and make to place this rule in /mtd/.htaccess:

RewriteEngine On
RewriteBase /mtd/

RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html$ index.php?page=$1&destination=$2&package=$3 [L,QSA]

RewriteRule ^([^/.]+)\.html$ index.php?page=$1 [L,QSA]

Upvotes: 1

Related Questions