.htaccess 在htaccess不工作的情况下重写

.htaccess 在htaccess不工作的情况下重写,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我有一个网站,其中有一个动态的网址只有3页。为此,我不支持php函数。所以我决定选择.htaccess重写规则,但我还没有任何运气 这是我的实际url:/index.php?mode=service&ini=1 我想把它改写成:/家庭影院 我亲自尝试,并使用以下代码: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.mysite\.com.au$ [NC] RewriteRule ^(.*)$ http://www.mysite.com.au

我有一个网站,其中有一个动态的网址只有3页。为此,我不支持php函数。所以我决定选择.htaccess重写规则,但我还没有任何运气

这是我的实际url:
/index.php?mode=service&ini=1

我想把它改写成:
/家庭影院

我亲自尝试,并使用以下代码:

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 redirect,所以我猜这是否会导致任何问题。index.php到www站点重定向工作正常,但不起作用。

使用
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]

像这样使用
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]

谢谢你的回复,但它不起作用。我需要那个浏览器和搜索引擎查看家庭影院的url,但服务器从索引url生成页面。我想这对你有帮助。我更新了问题,如果有帮助的话,我会把我的整个htaccess代码都放进去。我已经在我的更新部分修改了你的.htaccess,请在清除浏览器缓存后立即试用。还要报告access.log文件的相关部分。记录错误。记录文件。谢谢。它的工作就像一个符咒。我现在只有一个问题。我有一个动态生成的url。与链接。所以我不能编辑url。现在发生了什么。若我把上面的url写在浏览器中,它就可以正常工作。但当我点击实际链接时,它会显示旧的url.ok。我自己把它短路了。我在db中添加了额外的字段,并将链接的值放入,然后将其添加到url中。因此,它会动态生成我的url,htaccess可以完美地使用它。谢谢你的帮助!!!:-)谢谢你的回复,但它不起作用。我需要那个浏览器和搜索引擎查看家庭影院的url,但服务器从索引url生成页面。我想这对你有帮助。我更新了问题,如果有帮助的话,我会把我的整个htaccess代码都放进去。我已经在我的更新部分修改了你的.htaccess,请在清除浏览器缓存后立即试用。还要报告access.log文件的相关部分。记录错误。记录文件。谢谢。它的工作就像一个符咒。我现在只有一个问题。我有一个动态生成的url。与链接。所以我不能编辑url。现在发生了什么。若我把上面的url写在浏览器中,它就可以正常工作。但当我点击实际链接时,它会显示旧的url.ok。我自己把它短路了。我在db中添加了额外的字段,并将链接的值放入,然后将其添加到url中。因此,它会动态生成我的url,htaccess可以完美地使用它。谢谢你的帮助!!!:-)