用htaccess重写不起作用

时间:2012-09-05 12:30:52

标签: .htaccess mod-rewrite

我有一个网站,它只有3页的动态网址。为此,我不去寻找PHP功能。所以我决定选择.htaccess重写规则,但我还没有运气。

这是我的实际网址:/index.php?mode=service&inid=1

我想将其重写为:/home-theater

我自己尝试并使用此代码:

RewriteEngine On 

RewriteCond %{HTTP_HOST} !^www\.mysite\.com.au$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com.au/$1 [L,R=301]

Options +FollowSymLinks
DirectoryIndex index.php

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.mysite.com.au/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA]

我仍然无法让它发挥作用。

此外,我在此代码之前将index.php写入www重定向,所以我猜它是否会导致任何问题。 index.php到www网站重定向工作完美,但这不起作用。

1 个答案:

答案 0 :(得分:1)

像这样使用L标志:

RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA]

请注意,这不会更改浏览器中的网址,因为这会在内部将请求转发给index.php

此外,如果这不起作用,请在您的问题中提供完整的.htaccess。

更新:我在此处修改了您的.htaccess,请在清除浏览器缓存后立即试用:

DirectoryIndex index.php

Options +FollowSymLinks -MultiViews
RewriteEngine On 
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.mysite\.com.au$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com.au/$1 [L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^ http://www.mysite.com.au/ [R=301,L]

RewriteRule ^home-theater/?$ index.php?mode=service&inid=1 [L,NC,QSA]

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]