[英].htaccess that redirects to index.html, or to index.php if there are parameters
我正在尋找執行以下操作的.htaccess
:
對於訪問mydomain.com
用戶,服務器應從根目錄返回index.html
文件。
對於參觀用戶mydomain.com/something/
, mydomain.com/anything/123/
, mydomain.com/some%20encoded%20text
等,服務器應返回index.php
從根文件后通過文www.mydomain.com/
作為PHP $_GET
變量。
我嘗試了WordPress .htaccess
:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
但這會將所有內容重定向到index.php
文件。
通過httpd.conf
啟用mod_rewrite
和.htaccess
(如果尚未啟用),然后將此代碼放入DOCUMENT_ROOT/.htaccess
文件中:
RewriteEngine On
RewriteRule ^$ /index.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?f=$1 [L,QSA]
在index.php
您可以訪問$_GET['f']
變量,該變量將提供您請求的URI。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.