.htaccess偽靜態問題

來源:互聯網
上載者:User
.htaccess偽靜態問題

RewriteEngine on
Rewritebase /
ErrorDocument 404 /404.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

我一直用這個,這個有個缺點是什麼檔案都給包含進去了

比如你訪問whois.hangye5.com/womai.cn
這樣是可以的
但是如果訪問whois.hangye5.com/sitemaps/sitemap1.html
也會跑到index.php檔案裡去
我想這二個檔案不要都跑index.php裡去,要修改哪些


回複討論(解決方案)

#當目錄存在時不做重寫
RewriteCond %{REQUEST_FILENAME} !-d

#當檔案存在時不做重寫
RewriteCond %{REQUEST_FILENAME} !-f

whois.hangye5.com/sitemaps/sitemap1.html
也會跑到index.php檔案裡去,顯然 sitemaps/sitemap1.html 是不存在的

^(.*)$ 把一切不存在的東西都包括進去了,所以 404 設定不會起作用(index.php 總是存在的)
你需要在那個 .* 上做文章

sitemaps/sitemap1.html
這些也準備偽靜態
這個情況下我要怎麼辦

請教個偽靜態問題


我在弄那個whois查詢的時候偽靜態


http://whois.xxx.com/womai.cn這個的


RewriteEngine on
Rewritebase /
ErrorDocument 404 /404.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]


用了這個是可以的


但是我現在想在上面弄多一個檔案偽靜態
whois.xxx.com/sitemaps/sitemap1.html
whois.xxx.com/sitemaps/sitemap2.html
whois.xxx.com/sitemaps/sitemap3.html
這樣的


不知道怎麼弄,不知道怎麼在裡面新增內容
我自己添加的出問題了。

whois.xxx.com/sitemaps/sitemap1.html
這樣的會轉變成 index.php?domain=sitemaps/sitemap1.html
你在 index.php 中判斷處理一下就可以了

這個不好判斷的,還是要走到htaccess
因為這個東西又不是只有二樣。

建議你好好看看架構的路由指派

比較man呀
弄完這個還要去弄其他網站

RewriteEngine on
ErrorDocument 404 /404.html
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

RewriteRule ^(.*)/\w+/[A-za-z]+(\d+)\.html$ sitemaps/sitemap.php?domain=$2


這樣不行

RewriteRule ^(.*)/sitemaps/sitemap(\d+)\.html$ $1/sitemaps/sitemap.php?domain=$2

不行,他還是會跑到index.php裡去。這個問題估計在第一個偽靜態那裡出問題了

你那樣當然不行!
次序問題
RewriteRule ^(.*)/\w+/[A-za-z]+(\d+)\.html$ sitemaps/sitemap.php?domain=$2 [L]
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

RewriteEngine on
ErrorDocument 404 /404.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)/sitemaps/sitemap(\d+)\.html$ $1/sitemaps/sitemap.php?domain=$2
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

這樣的不行,估計是上一次影響了下一條

我有 [L] 你卻沒有

RewriteEngine on
ErrorDocument 404 /404.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)/\w+/[A-za-z]+(\d+)\.html$ sitemaps/sitemap.php?domain=$2 [L]
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

這樣也不行,真的

再向上調
RewriteRule ^(.*)/\w+/[A-za-z]+(\d+)\.html$ sitemaps/sitemap.php?domain=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

RewriteEngine on
ErrorDocument 404 /404.html
RewriteRule ^(.*)/\w+/[A-za-z]+(\d+)\.html$ sitemaps/sitemap.php?page=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

不行,有什麼辦法修改index.php 那一行,我那一行的作用是
whois.hangye5.com/womai.cn 後面是網域名稱

我行,你不行。不好說什麼了
可能是你的思路就錯了,因為給 RewriteRule 的串中不會含有網域名稱

這個大家都這樣弄的
whois.22.cn/womaicn

RewriteEngine on
ErrorDocument 404 /404.html
RewriteRule ^sitemaps/sitemap([0-9]+).html$ /sitemaps/sitemap.php?domain=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

這樣可以了

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.