2013-12-19 139 views
0

我正在开发一个php框架工作,我是.htaccess规则的新手。所以我需要使用.htaccess重定向 网址。链接从url中删除index.php htaccess

http://localhost/rinocabs/index.php?/Galary/Image/ 

应在.htaccess文件转换为这个

http://localhost/rinocabs/Galary/Image/ 

我包括这些规则

Options +FollowSymlinks 
RewriteEngine on 
rewritecond %{http_host} ^localhost/rinocabs/index.php?/Galary/Image/ [nc] 
rewriterule ^(.*)$ http://localhost/rinocabs/Galary/Image/$1 [r=301,nc] 

,但它不工作。请帮忙。

回答

4
Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

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

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

/rinocabs/index.php的/ Galary /图像/

本地主机/ rinocabs /的index.php?/ Galary/Image/

+0

有用。很好,但是对我的问题没有帮助。谢谢 –

+0

你用'RewriteCond%{THE_REQUEST}^[AZ] {3,} \ s( 。*)/ index \ .php?[NC]' – sas

+0

我对你的代码很感兴趣,我对htaccess代码有新意,请你一行一行解释一下这个代码:) 我得到了这样的结果 localhost/rinocabs/index.php?/ Galary/Image /结果为 localhost/rinocabs/ –

0

When in doubt, go the Codeigniter route!

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

基本上没有理由应包括的内容将是在重写规则和条件您的网址的域名部分,和你的病情正在时髦。查看上面的codeigniter示例,我们需要在表达式中完成以下操作:在路径中查找index.php段,并将其除去,然后重写以包含它。你的表情假设道路将永远是相同的......如果这是有道理的。使用localhost代替

+0

感谢您的回答。我去检查这一点。要尝试这个代码,我必须重新启动服务器? –

+0

事实上,它必须接受你的改变。尽管服务器重启很简单。 – Zarathuztra

+0

这对我不起作用:( –

0

请尝试以下代码:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 
0

请尝试下面的代码。它工作正常。

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [PT,L] 
+0

这会重写任何URL到index.php OP会以相反的方式威胁它! –

+0

谢谢我的朋友。我已经解决了这个问题。谢谢 –