.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]
這樣可以了