【问题标题】:Mod rewrite not working at all (phtml/php)Mod重写根本不起作用(phtml/php)
【发布时间】:2012-07-31 23:20:23
【问题描述】:

在我的网站上遇到 .htaccess 的一些问题。我正在尝试更改我网站的 URL 后缀。 URL 当前显示为:

www.example.com/about.phtml

我想删除 about.phtml 并用 about 替换它,所以它看起来像:

www.example.com/about

我使用的示例不是我在网站上需要的,所以我想要一些代码,我不必通过指定从哪个特定页面删除它,而是自动完成所有操作。

我尝试过使用 php 而不是 phtml,但没有成功。这是我正在使用的代码:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.phtml -f
RewriteRule ^(.*)$ $1.phtml

有什么想法我在这里做错了吗?

仅供参考:我的主机是 JustHost,他们允许我编辑我的 .htaccess,但如果有人听说过他们或对他们有任何问题,请告诉我,我与他们的技术支持人员交谈,他们无法再帮助我我不能帮助自己。

【问题讨论】:

  • 那么当你转到http://www.example.com/about 时会发生什么?什么都没发生?
  • 不行已经试过了。

标签: .htaccess mod-rewrite hosting php


【解决方案1】:

试试这个:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.phtml [NC,L]

【讨论】:

    【解决方案2】:

    这对我有用:

    RewriteEngine on
    RewriteRule ^/?([a-z]+)$ $1.phtml [L]
    

    【讨论】:

    • 好的,刚刚用过,现在也可以了!谢谢,我不确定要保留哪个以及为什么。
    • 这个答案不如上面接受的版本健壮,上面的那个会在重写 url 之前检查有效的文件名或目录。我会用那个。
    【解决方案3】:

    您可以先在 apache\conf\httpd.conf 文件中检查您的重写模式是否开启

    检查 httpd.conf 文件中的以下代码

    #LoadModule rewrite_module modules/mod_rewrite.so
    

    如果行上方存在哈希,则删除哈希并重新启动apache服务器

    之后你可以在你的 cakephp httaccess 文件中设置下面的代码

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME}\.phtml -f
        RewriteRule ^(.*)$ $1.phtml [NC,L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      相关资源
      最近更新 更多