簡體   English   中英

.htaccess 刪除“?page=”

[英].htaccess remove “?page=”

我有兩個問題,都相關:

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

如何使用 .htaccess 將其寫為: https://www.example.com/foo

第二部分

  1. 使用示例 url: 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,我用它來刪除控制器並將 controller 名稱作為路徑,將操作名稱作為路徑。

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM