我希望每個(gè)請(qǐng)求都被轉(zhuǎn)發(fā)到 index.php,但尊重請(qǐng)求是在哪個(gè)子文件夾中進(jìn)行的。我可以讓它們?nèi)哭D(zhuǎn)到根 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我不想對(duì)任何子文件夾進(jìn)行硬編碼以使其保持動(dòng)態(tài)。目前,我將其作為我的 .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貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊
# 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]
- 1 回答
- 0 關(guān)注
- 148 瀏覽
添加回答
舉報(bào)
0/150
提交
取消