.htaccess重写不工作

问题描述:

这已被要求分配在互联网上,这里在stackoverflow。 但我不能得到它的工作。 (使用.htacces第一次) 什么即时试图做的是一些简单的东西:.htaccess重写不工作

  1. 从URL中移除www
  2. 从url中删除.php
  3. 从主页删除/index如果链接回它。

根据我的网站主办公司,这是他们所使用的:
的Apache 2.2+和PHP 5.3+ - MySQL的5.1+

的.htacces文件位于根文件夹的index.php 我已尝试分配的东西,但这是我现在得到的:

RewriteEngine On 
#www to non www 
RewriteCond %{HTTP_HOST} !^mysite.se$ [NC] 
RewriteRule ^(.*)$ http://mysite.se/$1 [L,R=301] 

#remove .php 
RewriteCond %{HTTP_HOST} ^mysite\.se$ [NC] 
RewriteCond %{QUERY_STRING} !internal=1 [NC] 
RewriteRule ^(.*)\.php$ $1 [L,R=301] 

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

先感谢您的任何帮助,您可以提供。

+0

重写日志说什么? – Waygood 2013-03-07 13:34:58

+0

“不工作”是什么意思? – 2013-03-07 13:36:20

+1

你还没有说过这三个中的哪一个不适合你,反而会发生什么。 – hakre 2013-03-07 13:36:21

您以错误的方式使用.htaccess

不得使用htaccess的生成一个友好的URL,您必须使用它来一个友好的URL转化为真正的

RewriteEngine On 
RewriteBase/

#redirect www.mysite.se to mysite.se 
RewriteCond %{HTTP_HOST} !^mysite.se$ [NC] 
RewriteRule ^(.*)$ http://mysite.se/$1 [L,R=301] 

#redirect mysite.se/page to mysite.se/page.php (transparent) 
#as this rule is extremely permissive, we desactivate it when we're calling 
#a real file, to avoid this kind of situation : mysite.se/img/mylogo.jpg.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ $1.php [L] 

#redirect mysite.se/index to mysite.se/ (visible) 
RewriteRule ^index$/[L,R=301] 

在你的代码,使用友好的URL,和让htaccess重定向它。

如果你不使用这种方法,你就会陷入一个自我毁灭的模式,试图page.php重定向到page(获得不错的网址),并重定向到pagepage.php(因为你的应用程序只知道page.php) 。

+0

所以我应该写没有.php我的网址? – objectnobb 2013-03-07 14:06:29

+0

是的,无处不在使用.php的URL。 – zessx 2013-03-07 14:07:55

+0

多数民众赞成在不方便:( – objectnobb 2013-03-07 14:14:23