【问题标题】:Rewrite url - Rediriger sans index.php重写 url - Rediriger sans index.php
【发布时间】:2019-02-15 16:31:31
【问题描述】:

我的 URL 类型为:www.mysite.fr,对于任何页面:www.mysite.fr/index.php/test

希望 www.mysite.fr/test 显示 www.mysite.fr/index.php/test (没有 index.php 更漂亮!)

我试过了,但是:www.mysite.fr/test 显示主页而不是测试页面

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

【问题讨论】:

    标签: .htaccess web url-rewriting


    【解决方案1】:

    试试这个:

    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/(.*)index\.php/(.*)\sHTTP.*$ [NC]
    RewriteRule ^ /%1%2 [R=301,L]
    RewriteCond %{REQUEST_URI} !index\.php
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    第二行删除index.php 外部。

    第五行将请求重定向到内部原始路径。

    注意:清除浏览器缓存测试

    【讨论】:

    • 谢谢,但它仅适用于本地主机。网站显示“找不到文件”
    • .htaccess 在主根目录中吗?
    【解决方案2】:

    您的方法适用于我的本地主机,但不适用于我的在线网站。这是我认为阻塞的第 5 行,但我不明白为什么还要在 index.html 之前添加斜杠。 有人有想法吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-25
      • 2013-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      相关资源
      最近更新 更多