【问题标题】:HTACCESS Rewrite Rule for Query String in PHPPHP中查询字符串的HTACCESS重写规则
【发布时间】:2021-08-24 10:08:35
【问题描述】:

我有我的网址https://example.com/?hfgshdsds

我需要重写一个规则,即使我删除了问号,链接也会和以前一样,所以我的网址需要是https://example.com/hfgshdsds

目前在我的 .htaccess 文件中,我只有打开不带扩展名 .php 的 php 的规则。

RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

谢谢!

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting friendly-url


    【解决方案1】:

    使用您显示的示例,请尝试遵循 htaccess 规则文件。请确保在测试您的 URL 之前清除您的浏览器缓存。

    RewriteEngine On
    ##keep redirection Rules first then keep rest of rules.
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
    
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule !.*\.php/?$ %{REQUEST_FILENAME}.php [QSA,L]
    
    ##Adding new rule here for non-existing pages here.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/?$ index.php?$1 [QSA,L]
    

    【讨论】:

    • 非常感谢,它对我有用,我认为这对于需要这种规则的每个人来说都是一个很好的解决方案。
    猜你喜欢
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 2019-10-31
    相关资源
    最近更新 更多