iT邦幫忙

1

IIS URL Rewrite 以及 URL網址列顯示問題

  • 分享至 

  • twitterImage

不好意思詢問各位大神
公司要我寫UrlRewrite希望把
http://192.xxx.xxx.xxx/file_name/index.php?id=image01
to
http://192.xxx.xxx.xxx/file_name/image01

我的想法是

  1. 把index.php去掉
  2. 抓Query_string id=
  3. 將Query_string Value 塞回去Url

但問題
A. {R:0} 或是 {C:1} 這是要怎麼看
這是IIS GUI畫面 雖然有出{R:0} {C:1}
但如果單純用web.config的話要怎麼看?? (code在下面)
https://ithelp.ithome.com.tw/upload/images/20210324/20120558wjeC2XPvI4.png

B. 假如使用者就是在網址列上打index.php?id=xxx 我能更改 使用者的畫面嗎??
Web.config設定好後 (code在下面)
現在網址打
http://192.xxx.xxx.xxx/file_name/index.php?id=image01 正常網站
http://192.xxx.xxx.xxx/file_name/image01 正常網站
可是公司企劃似乎是要我做成
https://ithelp.ithome.com.tw/upload/images/20210324/20120558ubIYqOSpRA.png
變成這樣
https://ithelp.ithome.com.tw/upload/images/20210324/20120558sSA3FopM7g.png

因為我有問如果id(key)打錯要出什麼畫面,結果企劃說寫 urlRewrite就不會有id(key)錯的問題....
可以做到上面那種要求嗎?? 一直以為Rewrite就只是網站背後重新送個url出去
還是可以讓 /index.php?id=image01 失去效果
只讓 /image01 有效果
這樣不知道可不可以

謝謝大神們

這是網路上抓的code但還在搞懂中...
那個{R:1} 想了很久,還是不懂QQ
web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="rewrite">
                    <match url="^(.*)$" />
                    <conditions logicalGrouping="MatchAll">
						<add input="{HTTP_HOST}" pattern="^(.*)$" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
						<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="./index.php?id={R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

code 關鍵字 => iis urlrewrite index.php 刪除

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

1 個回答

0
咖咖拉
iT邦好手 1 級 ‧ 2021-03-25 09:27:43
最佳解答
http://192.xxx.xxx.xxx/file_name/index.php?id=image01

通常有這樣結構的網址
應該是在index.php裡面去抓id參數 然後跳轉到圖片或將圖片帶入頁面裡
找看看index.php 對應的程式在哪

IIS要顯示圖片 用絕對路徑也能抓到

謝謝你~~
不好意思後來一步步慢慢摸出來了
十分感謝

我要發表回答

立即登入回答