1

我有一个网站,只有 3 页的动态 url。为此,我不使用 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 站点的重定向工作完美,但这不起作用。

4

1 回答 1

1

像这样使用L标志:

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

请记住,这不会更改浏览器中的 URL,因为这会在内部将请求转发到您的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]
于 2012-09-05T18:44:31.037 回答