我的htaccess工作不正常

时间:2014-02-03 03:11:48

标签: php apache .htaccess mod-rewrite redirect

以下是我的.htaccess内容:

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

以下链接正常运行:

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

该页面成功传递了$_GETindex.php?page=page-name

然而,以下链接显示404错误

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

此网址应传递$ _GET值,例如:

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

这适用于带有XAMPP服务器的Windows 8.1和带有cPanel的远程服务器,但在我使用LAMP Stack转移到Ubuntu(最新版本)之后,它已不再有效。

执行命令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# 

1 个答案:

答案 0 :(得分:1)

您需要更正RewriteBase并将此规则放在/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]