微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

.htaccess 删除“?page=”

如何解决.htaccess 删除“?page=”

我有两个相关的问题:

  1. 使用示例网址:https://www.example.com/?page=foo.php

我如何使用 .htaccess 将其写成:https://www.example.com/foo

第二部分

  1. 使用示例网址:https://www.example.com/?page=directory/bar.php

我如何使用 .htaccess 将其写成:https://www.example.com/directory/bar

编辑:

回复显示您当前的.htaccess

# PHP -- BEGIN cPanel-generated handler,do not edit
# Set the “ea-PHP74” package as the default “PHP” programming language.  
 <IfModule mime_module>
   AddHandler application/x-httpd-ea-PHP74___lsPHP .PHP .PHP7 .phtml
 </IfModule>
# PHP -- END cPanel-generated handler,do not edit

## Redirects the index.PHP file to the root domain
RewriteRule ^index.PHP$ https://www.digitleSEO.com/ [R=301,L]

#redirect  /file.PHP to /file
RewriteRule ^(.+).PHP$ /$1 [L,R]
# Now we will internally map /file to /file.PHP
RewriteCond %{REQUEST_FILENAME}.PHP -f
RewriteRule ^(.*)/?$ /$1.PHP [END]

解决方法

这应该对你有用。

RewriteEngine on
#redirect /?page=foobar.php to /foobar
RewriteCond %{THE_REQUEST} \s/(?:index\.php)?\?page=([^.]+)\.php [NC]
RewriteRule .* /%1? [L,R]
###the rule bellow will internally forward the new URL to the old one
# not an existent file
RewriteCond %{REQUEST_FILENAME} !-f
#not a directory
RewriteCond %{REQUEST_FILENAME} !-d
#rewrite the request /foo/bar to /?page=foo/bar.php
RewriteRule ^(.+)/?$ /?page=$1.php [L,END]
,

这是我的文件 htaccess,我用它来删除控制器并将控制器名称保留为路径,将操作名称保留为路径。

<IfModule mod_rewrite.c>

    RewriteEngine on
    ErrorDocument 404 http://shop.local/error/index

    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f

    RewriteRule ^(.*)/(.*) index.php?controller=$1&action=$2
</IfModule>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。