htaccess重写让url部分无法正常工作

时间:2015-04-22 18:48:48

标签: .htaccess url-rewriting

我正在尝试将网址example.com/parts/toolbucket/part.php?id=1重写为example/toolbucket/part/1

我的大部分.htaccess都在工作,但重写的最后一部分不起作用。

这是我的.htaccess

Options -Indexes
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} \s/parts/([^\s]+)\s [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /parts/$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

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

RewriteRule ^toolbucket/([0-9]*)$ ./part.php?id=$1

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

因为您缺少规则中的目录part。如果您希望自己的网址为example.com/toolbucket/part/1

替换此

RewriteRule ^toolbucket/([0-9]*)$ ./part.php?id=$1

有了这个。

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^toolbucket/part/([0-9]*)/?$ /parts/toolbucket/part.php?id=$1 [L]