iT邦幫忙

1

Apache 透過 htaccess 隱藏 php 副檔名(mod_rewrite)

首先安裝好 apache 後,啟用 rewrite 功能

$ a2enmod rewrite

然後再到 /etc/apache2/apache2.conf 添加內容

$ nano /etc/apache2/apache2.conf 

內容為

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

記得將路徑設為你的網站根目錄路徑呦!

接著將 apache reload

service apache2 reload

然後去你的網站根目錄中添加檔案為 .htaccess,並加入以下內容

Options -Indexes
Options +FollowSymlinks
RewriteEngine on

在同一個 .htaccess 檔案中添加 RewriteRule,就像這樣

Options -Indexes
Options +FollowSymlinks
RewriteEngine on

RewriteRule ^admin/index$ admin/index.php

這樣只要訪問路徑 /admin/index 就等於是訪問了 /admin/index.php,apache已經幫你隱藏副檔名了

參考

https://ianakaberlin.medium.com/apache-%E7%B6%B2%E9%A0%81%E4%BC%BA%E6%9C%8D%E5%99%A8-%E9%80%8F%E9%81%8E-htaccess-%E9%9A%B1%E8%97%8F%E7%B6%B2%E5%9D%80%E7%9A%84-php-%E5%89%AF%E6%AA%94%E5%90%8D-mod-rewrite-php-apache-%E4%BC%8A%E6%81%A9%E8%B8%A9%E5%9D%91%E7%AD%86%E8%A8%98-3d6a4b80d223


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言