【问题标题】:How to remove .php extention from url using htaccess? [duplicate]如何使用 htaccess 从 url 中删除 .php 扩展名? [复制]
【发布时间】:2017-09-26 10:28:08
【问题描述】:

如何删除我的 url 和问号替换为斜杠的 php 扩展

http://eeroju.in/telugu/post.php?post_id=348 

http://eeroju.in/telugu/post/post_id/348 

我正在使用下面的代码

        RewriteEngine On

        # Unless directory, remove trailing slash
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^([^/]+)/$ http://localhost/telugu/$1 [R=301,L]

        # Redirect external .php requests to extensionless url
        RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
        RewriteRule ^(.+)\.php$ http://localhost/telugu/$1 [R=301,L]

        # Resolve .php file for extensionless php urls
        RewriteRule ^([^/.]+)$ $1.php [L]
        ---
        <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^route-page\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /route-page.php [L]
        </IfModule>

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    尝试添加以下设置

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

    【讨论】:

      【解决方案2】:

      将其包含在您的 .htaccess 代码中 **

       Options +Indexes +MultiViews
      

      ** 在您的 html 代码中,要链接到另一个页面,请执行此操作

      <a href="next-page">Click here</a> to go to next page
      

      next-page 是一个 .php 文件,但可以在没有 .php 扩展名的情况下在浏览器上呈现。

      【讨论】:

      • 我不认为这回答了问题——主要问题是如何让 PHP 文件在没有 .php 扩展名的情况下由 PHP 运行。它需要更改 Apache 配置。
      猜你喜欢
      • 2013-04-06
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-10
      相关资源
      最近更新 更多