簡體   English   中英

.htaccess重定向到index.html或index.php(如果有參數的話)

[英].htaccess that redirects to index.html, or to index.php if there are parameters

我正在尋找執行以下操作的.htaccess

  1. 對於訪問mydomain.com用戶,服務器應從根目錄返回index.html文件。

  2. 對於參觀用戶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.

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