亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何編寫 .htaccess 以將所有請求轉發到它們發出的任何子文件夾中的 index.php

如何編寫 .htaccess 以將所有請求轉發到它們發出的任何子文件夾中的 index.php

PHP
紅糖糍粑 2023-04-21 10:14:06
我希望每個請求都被轉發到 index.php,但尊重請求是在哪個子文件夾中進行的。我可以讓它們全部轉到根 index.php,但不是特定子文件夾中的 index.php。示例:site.com/testurl > site.com/index.phpsite.com/admin/testurl > site.com/admin/index.phpsite.com/randomname/randomname > site.com/randomname/index.php我不想對任何子文件夾進行硬編碼以使其保持動態。目前,我將其作為我的 .htaccess 文件:DirectoryIndex index.php# enable apache rewrite engineRewriteEngine onRewriteCond %{HTTPS} offRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]# Deliver the folder or file directly if it exists on the serverRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d# Push every request to index.phpRewriteRule ^(.*)$ index.php [QSA]額外功勞(不確定 .htaccess 是否可行):讓它知道 index.php 是否在子目錄中,如果不在則回退到根目錄 index.php
查看完整描述

1 回答

?
智慧大石

TA貢獻1946條經驗 獲得超3個贊

# Determines whether the request doesn't end with index.php:

RewriteCond %{REQUEST_URI} !/index.php$


# Redirect to the requested path, followed by index.php:

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)/(.*)$    /$1/index.php [L]


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !/index.php$

RewriteRule ^(.*) /index.php [L]


查看完整回答
反對 回復 2023-04-21
  • 1 回答
  • 0 關注
  • 144 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號