【问题标题】:.htaccess problems, impossible for me to remove .php.htaccess 问题,我无法删除 .php
【发布时间】:2023-03-31 12:21:01
【问题描述】:

我需要你的帮助。 我有这个网址:wwww.myurl.com/?verfy=CDPOR888wwww.myurl.com/index.php?verfy=CDPOR888

我想变成这样:www.myurl.com/CDPOR888

请帮忙,我怎样才能用 .htaccess 做到这一点?

我在 .htaccess 中尝试了这段代码,但没有工作:

RewriteRule ^([^/]*)\.php$ /?perms_verify=$1 [QSA,L,NC]

但问题是 .php,当我删除它时出现错误。

注意:.htaccess 不区分大小写

【问题讨论】:

    标签: php .htaccess url url-rewriting


    【解决方案1】:

    你可以使用这条规则:

    RewriteEngine On
    
    # request is not for a file
    RewriteCond %{REQUEST_FILENAME} !-f
    # request is not for a directory
    RewriteCond %{REQUEST_FILENAME} !-d
    # rewrite to destination path
    RewriteRule ^([\w-]+)/?$ ?verfy=$1 [QSA,L]
    

    【讨论】:

      【解决方案2】:

      请替换这条规则!

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

      【讨论】:

      • 这只会将/CDPOR888 重写为/CDPOR888.php,这将导致404,因为CDPOR888.php 不存在。
      • 你试过"RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f //使用这个规则 RewriteRule ^([^\.]+)$ $1.php [NC,L]"
      • 有趣,我得到了 404,因为 CDPOR888.php 不存在。
      • 你能上传你的 .htaccess 文件吗?
      • 这与您的答案中的 3 行相同。
      【解决方案3】:

      将您的 .htaccess 文件更新为

      DirectoryIndex index.php
      
      # remove the next 3 lines if you see a 500 server error
      
      
      FileETag none
      ServerSignature Off
      
      Options All -Indexes
      
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteRule ^([0-9a-zA-Z_-]{1,16})$ index.php?verify=$1 [L]
      </IfModule>
      

      在 www.myurl.com/index.php 页面上,编写逻辑以使用 GET 方法捕获验证值并进行进一步操作

      【讨论】:

        猜你喜欢
        • 2015-04-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-23
        • 2013-08-25
        相关资源
        最近更新 更多