iT邦幫忙

1

網址mod_rewrite要如何寫

com 2022-01-27 17:10:521075 瀏覽

我需要將下面網址
www.xxx.com.tw/modules/index.php?n=aaa
變成
www.xxx.com.tw/modules/aaa
我目前在NGINX進行下面設定可以正常得到我想要的結果

    location ~ /modules/([A-Za-z0-9_-]+)/? {
		try_files $uri /modules/index.php?n=$1;
    }

但是在Apache我就不知道要如何寫.htaccess
是否有前輩可以指導?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
1
Felix
iT邦研究生 2 級 ‧ 2022-01-28 07:15:42

規則有 L 修飾字元時,表示不會繼續配對。

# 啟用轉寫引擎
RewriteEngine on

# 指定轉寫根目錄路徑
RewriteBase /

# 建立轉寫規則
RewriteRule ^/modules/([A-Za-z0-9_-]+)/?$ /modules/index.php?n=$1 [L]
1

要依您的.htaccess放置位置而調整

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([A-Za-z0-9_-]+)/?$ index.php?n=$1 [L]
</IfModule>

放index.php網頁同一層試試看

0
RewriteRule ^/modules/([A-Za-z0-9_-]+)/?$ /modules/index.php?n=$1 [L]

来源

我要發表回答

立即登入回答