2011-11-22 79 views
1

我试图改变我的.htaccess文件,所以如果我去:修改.htaccess使URL变量=真正改变为URL /变量?

http://www.example.com/index.php?login=true,它去http://www.example.com/login

我目前有这个代码,它删除index.php(这使得上面看起来像http://www.example.com/?login=true)。

RewriteEngine On 
#remove index.php 
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] 
RewriteCond %{THE_REQUEST} !/system/.* 
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L] 
RewriteCond %{THE_REQUEST} ^GET 
+0

我肯定会需要其他变体 - 基本上任何有东西=东西 – Jared

回答

0

我会设置你的重写规则的其他方式:

RewriteEngine On 
RewriteRule ^login$ /index.php?login=true 

这样,如果用户浏览到http://yourserver.com/login实际使用的页面http://yourserver.com/index.php?login=true,但第一个URL在浏览器中显示。我认为这是你想要达到的目标。

如果你真的需要做的是在你要的方向,你可以尝试这样的事:

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^login=true$ 
RewriteRule ^index\.php$ /login [L,R=301] 

的还有额外的查询参数,则会失败。

如果你想重定向到http://yourserver.com/index.phphttp://yourserver.com可以简单地添加以下重写规则:

RewriteRule ^index\.php$/[L,R=301] 
+0

他可能也需要它,或者他可能已经在他的PHP代码中实现了所有。我怀疑他想要的是没有断开链接,所以如果某些链接到这些旧页面中的某一个,他希望这个新的链接显示出来。 –

+0

这个效果如何去http://yourserver.com/index.php?我应该澄清,但如果有人去http://yourserver.com/index.php,它应该只显示http://yourserver.com – Jared

+0

请参阅我的编辑删除index.php。 –

0

您需要检查在的RewriteCond的QUERY_STRING。我认为这应该这样做:?

RewriteEngine On 
#remove index.php 
RewriteCond %{QUERY_STRING} ([^=]*)=true [NC] 
RewriteCond %{THE_REQUEST} !/system/.* 
RewriteRule ^index\.php /%1? [R=301,L] 

这应该重定向任何具有的index.php =真实/行动

+0

使用示例,'http://example.com/index.php?login = true'重定向到'http://example.com/login?login = true'。 – Jared

+0

确实,你应该添加一个?重定向到用像Sarel Botha这样的新空字符替换现有的查询字符串。我编辑了包含这个的答案。 (并简化了一下规则)。 – AVee

0

尝试在.htaccess以下在example.com的根目录

RewriteEngine On 
RewriteBase/

#rewrite http://www.example.com/anything to http://www.example.com/index.php?anything=true 
RewriteCond %{REQUEST_URI} ^/([-a-zA-Z0-9]+)$ [NC] 
RewriteCond %1 !system [NC] 
RewriteRule . index.php?%1=true [L] 


#301 redirect requests for example.com/index.php?anything=true to example.com/anything 
RewriteCond %{REQUEST_URI} ^/index\.php$ [NC] 
RewriteCond %{QUERY_STRING} ^([^=]+)=true$ [NC] 
RewriteRule . /%1? [L,R=301]