2
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d # not an existing dir
RewriteCond %{REQUEST_FILENAME} !-f # not an existing file
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f # and page.php exists
# redirect to the physical page
RewriteRule ^(.*)$ $1.php [L]
# otherwise, redirect to serve.php
RewriteRule^/serve.php [L]
RewriteRule ^(\w+)$ ./serve.php?id=$1
因此,在代碼的第一部分,我只需將http轉換爲https即可。我的目標是,我可以使用沒有.php
的網址,但在我的舊代碼中,我遇到了如果我這樣做的問題,它被用作我的serve.php頁面的ID。所以,如果使用https://example.com/contact
它就像https://example.com/serve.php?id=contact
,但我希望它的工作爲https://example.com/contact.php
,但另一方面,我希望不是路線或文件的ID仍應作爲IDS工作。我的舊代碼是...如何讓htacess區分文件和ID
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(\w+)$ ./serve.php?id=$1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
上帝保佑你,終於有人誰不報道我要重複,而且有利於真實的。繼續吧! –
我會在7分鐘內給你一個徽章.. –