【问题标题】:Redirect index.php request to http://localhost/website/ using .htaccess使用 .htaccess 将 index.php 请求重定向到 http://localhost/website/
【发布时间】:2013-04-03 04:08:10
【问题描述】:

我对配置我的 .htaccess 还不是很熟悉,所以请帮帮我。

我有一个指向 index.php 的链接,但我不希望 index.php 出现在我的网址中

eg. 
http://localhost/website/index.php

我希望它被重定向到根文件夹

http://localhost/website/ 

所以我尝试寻找答案,这就是我到目前为止所得到的。

RewriteEngine on

Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://localhost/website/$1 [R=301,L]

现在,当我尝试在本地网站中单击主页时,而不是将我重定向到

http://localhost/website

它被重定向到这个 -

http://localhost/Applications/XAMPP/xamppfiles/htdocs/website/localhost/website/

谁能解释这是怎么回事?

【问题讨论】:

  • 不。不是框架。

标签: .htaccess mod-rewrite


【解决方案1】:

你试过这个吗

RewriteRule ^(.*)$ /index.php/$1 [L] 

【讨论】:

    【解决方案2】:

    我对 .htaccess 所做的更改不会在我刷新页面后立即生效。我花了一些时间来清除缓存以查看效果。我尝试了不同的方法来解决我的问题:

    Options +FollowSymLinks
    RewriteEngine on
    
    #RewriteCond %{THE_REQUEST} ^.*/index.php
    #RewriteRule ^(.*)index.php$ http://localhost/website/$1 [R=301,L]
    
    #RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /?(.*)/index\.php
    #RewriteRule ^ /%1 [L,R=301]
    
    #RewriteRule ^(.*)$ /index.php/$1 [L] 
    

    带有# 的行并没有解决我的问题,可能是因为缓存没有被清除,但无论如何 下面的这一行解决了我的问题,但在我真正看到结果之前我花了 5 次清除缓存。

    RewriteRule ^index.php(.*)$ http://localhost/website/$1 [R=301,NC]
    

    我从htaccess generator得到它

    【讨论】:

      猜你喜欢
      • 2015-04-10
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      相关资源
      最近更新 更多