我正在嘗試從靜態頁面的 url 中洗掉檔案擴展名
sitename.com/page.php→sitename.com/page
我這樣做是為了讓我的 wp url 看起來像這樣(如果重要的話)
sitename.com/wp/→sitename.com/
FTP 看起來像這樣:
- root directory
- static php files
- htaccess file
- wp folder
將此添加到.htaccess沒有任何作用
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
當前.htaccess內容:
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
ErrorDocument 403 /403.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
如何僅通過在.htaccess檔案中添加代碼來實作這一點?先感謝您!
uj5u.com熱心網友回復:
我意識到檔案被覆寫了,所以我唯一能做的就是為每個靜態檔案(即 page/index.php)創建單獨的檔案夾,這樣我就可以實作這個sitename.com/page.php→sitename.com/page
uj5u.com熱心網友回復:
洗掉檔案擴展名的步驟是:
- 登錄您的 cPanel 帳戶。
- 轉到檔案管理器- 在檔案部分
- 在檔案管理器中,轉到右上角的設定按鈕。
- 在將出現的首選項視窗中,選中顯示隱藏檔案(點檔案)選項。單擊“保存”按鈕應用設定。
- 現在導航到 .htaccess 檔案。如果檔案不存在,您將需要創建它。
- 單擊檔案管理器頂部選單中的編輯按鈕。
- 將以下行添加到 .htaccess 檔案中。單擊“保存更改”按鈕,然后單擊“關閉”按鈕。
#remove php 檔案擴展名-eg https://example.com/file.php會變成https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
- 現在 Apache Web 服務器將從 URL 中洗掉 .php 擴展名。
要洗掉 .html 擴展名,請使用:
#remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
您還可以通過 FileZilla 等 FTP 客戶端在您的虛擬主機帳戶上編輯 .htaccess 檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/360521.html
下一篇:過濾唯一值
