顯示包含「apache」標籤的文章。顯示所有文章
顯示包含「apache」標籤的文章。顯示所有文章

Apache ~ .htaccess not read .htaccess not working

會找這問題是因為......

yii的/user/login連結跑不出來

not found

就覺得應該是rewrite沒開

跑去開了rewrite

sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart


發現連結依然找不到......

燈愣.....

為此我還實際測試.htaccess倒底是否working

結果working...

上網找找找

才看到有人說是Allowoverride的問題

修改過後才真的可以了 = =

sudo vi /etc/apache2/sites-available/default

把DocumentRoot /var/www

裡面的AllowOverride改成All

AllowOverride All

<Directory /var/www/>

裡面也要改

AllowOverride All

儲存

再下指令重開apache就好了

sudo /etc/init.d/apache2 restart


Ubuntu ~ enable apache mod_rewrite

sudo a2enmod rewrite

然後再restart apache

sudo /etc/init.d/apache2 restart

reference
http://thinkdiff.net/ubuntu-linux/ubuntu-enable-mod_rewrite-in-apache-server/

Apache ~ redirect 404 error to a custom page

在.htaccess裡加入這段

#404
ErrorDocument 404 /404.php

而我放的是

#404
ErrorDocument 404 /nzxt2/404.php

因為我的檔案是在nzxt2裡XD

reference
http://www.htaccessbasics.com/404-custom-error-page/

Apache ~ redirect domain.com to www.domain.com

xxx.com to www.xxx.com
------------------------------------------------------------------------------------------------
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xxx\.com
RewriteRule ^(.*)$ http://sfdgsdgewrg.qwertqrwtqegagesfag.com/$1 [R=permanent,L]
------------------------------------------------------------------------------------------------


www.xxx.com to xxx.com
------------------------------------------------------------------------------------------------
RewriteEngine on
RewriteCond %{HTTP_HOST} !^xcbsegsertfgesrtg\.com$ [NC]
RewriteRule ^(.*)$ http://xcvbsdfhgbrsgsdfgvb.com/$1 [R=301,L]

------------------------------------------------------------------------------------------------

reference
http://www.cyberciti.biz/faq/apache-redirect-domaincom-to-wwwdomaincom/

Apache ~ prevent hot linking images, block direct image Linking

這東西就是為了避免其他網站連結你的圖片用

假設網址是http://www.ggyy.com/website/


.htaccess
--------------------------------------------------------------------------------------------------
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.ggyy.com/website/.*$ [NC]
RewriteRule ^.*\.(bmp|tif|gif|jpg|jpeg|jpe|png)$ - [F]
--------------------------------------------------------------------------------------------------

把它放到圖片資料夾~~~~~我的圖片資料夾叫img

所以是放在img/裡


這樣人家從別地方連你的圖片
<img src="http://www.ggyy.com/website/img/gy.jpg" />

就會連不到甚麼東西

可是如果透過他本地網址取圖片就可以~~


reference
http://www.cyberciti.biz/faq/apache-mod_rewrite-hot-linking-images-leeching-howto/

http://www.selfseo.com/story-18469.php

Apache ~ disable directory browsing, block directory listing

open httpd.conf

modify

Options Indexes FollowSymLinks

to

Options FollowSymLinks


reference
http://forums.devshed.com/apache-development-15/disabling-directory-browsing-in-linux-apache-10533.html

Apache ~ Rewrite example ~

.htaccess
--------------------------------------------------------------------------------
RewriteEngine on

RewriteRule ^products/([A-Za-z0-9_]+)/?$ category.php?c=$1 [L]

RewriteRule ^products/([A-Za-z0-9_]+)/([A-Za-z0-9_]+)/?$ product.php?name=$1&id=$2 [L]
--------------------------------------------------------------------------------

這個範例是

假如.htaccess所在的目錄~~~是在網址http://qoo.com

那麼連到
htpp:/qoo.com/products/xxxxxxxxxxxxxxxxxxxxx

實際上會連到
htpp:/qoo.com/catogory.php?c=xxxxxxxxxxxxxxxxxxxxx


連到
htpp:/qoo.com/products/xxxx/yyyyyyyyyy

實際上會連到
htpp:/qoo.com/product.php?name=xxxx&id=yyyyyyyyyy

Apache ~ Password Log in (Apache密碼驗證登入)

其實看這網站就好了.........XD
http://blog.chinaunix.net/u/9817/showart_290572.html


但我另外貼一下我試成功的設定檔~

在httpd.conf多加
------------------------------------------------------------------------------------------------
<Directory "d:/wamp/www/test/">
Options Indexes MultiViews
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
------------------------------------------------------------------------------------------------


d:/wamp/www/test/.htaccess
------------------------------------------------------------------------------------------------
AuthName "frank share web"
AuthType Basic
AuthUserFile D:/wamp/www/test/.htpasswd
<LIMIT GET>
require valid-user
</LIMIT>
------------------------------------------------------------------------------------------------


d:/wamp/www/test/.htpasswd
------------------------------------------------------------------------------------------------
bitty:1234
------------------------------------------------------------------------------------------------

Apache Password Log in ~ Could not open password file:(Apache 密碼驗證問題)

這個問題........................

是因為權限的問題

我一直弄不出~~~~~~~以為是密碼沒弄好~~~~~

.htpasswd檔案

可是後來才發現不是@@

去apache_error.log看了才知道~

[Fri Nov 27 00:08:15 2009] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified.  : Could not open password file: D:/wamp/test/.htpasswd

其實在test裡面真得有這檔案~~~~~~~只是Apache沒有權限讀取他

問題就出在這~~~

後來我改了AuthUserFile D:/.htpasswd

把檔案丟到D裡面~~~~~~乾~~~~~~就成功了~~~~感動Q_Q...........


http://phorum.study-area.org/index.php?topic=33840.0

http://www.linuxquestions.org/questions/linux-networking-3/trouble-with-apache-password-file-473957/

(後來發現我路徑打錯XD~~~~不過權限問題也是其中之一啦XD)

Apache ~ Alias

一種簡單的redirect方法~~~

假設apache的root是d:/wamp/www

那加

Alias /xxx "d:/wamp/www/qoo/"

這段到httpd.conf~~~~~

連線localhost/xxx就會連到localhost/qoo

網址是123.123.123.123/xxx

但實際上是連到123.123.123.123/qoo

Apache - VirtualHost ~ different URL direct to different Directory

我會要用這種東西是因為~

我申請了DNS~~~(抖咩孽)

hinet的DNS~~~~~~他提供5個網域名稱讓你對到指定的IP位址

所以我希望不同的DNS對到同個IP位址~

然後電腦依據不同的URL指定到不同的目錄~~~~

例如我打

www.qoo.com.tw~~~~ip指到123.123.123.123
但是卻是開啟123.123.123.123這台電腦的某個目錄~qoo

www.bitty.com.tw~~~~ip指到123.123.123.123
但是卻是開啟123.123.123.123這台電腦的某個目錄~bitty


要達到這目的~~~我用的方法是VirtualHost

設定在httpd.conf裡面
--------------------------------------------------------------------------------------------

NameVirtualHost 123.123.123.123:80

<VirtualHost www.bitty.com.tw>
DocumentRoot D:/wamp/www/bitty
</VirtualHost>

<VirtualHost localhost>
DocumentRoot D:/wamp/www/ggyy
</VirtualHost>

<VirtualHost www.qoo.com>
DocumentRoot D:/wamp/www/qoo
</VirtualHost>
--------------------------------------------------------------------------------------------

假設www.qoo.com跟www.bitty.com都是連到123.123.123.123

那當使用者瀏覽網址

www.bitty.com就是連到目錄 D:/wamp/www/bitty

www.qoo.com就是連到目錄 D:/wamp/www/qoo


就醬子= =.......

我上網看了很多資料~~~只是一直用不出~~~~到最後找到這個網頁才用出來
http://freebsd.lab.mlc.edu.tw/apache/VirtualHost.shtml

也是介紹VirtualHost
http://ms.ntcb.edu.tw/~steven/article/namebase_vh.htm

介紹很多apache方法
http://phorum.study-area.org/index.php?topic=17120.0

國外網站~~~介紹很多redirect的方法
http://www.yolinux.com/TUTORIALS/ApacheRedirect.html

Apache ~ block china IP 阻擋中國大陸ip

今天某人問我的~~~這網頁有方法~~~

http://www.parkansky.com/china.htm

如果不想要自己的網站給大陸進來~~~~就把它複製貼到.htaccess檔~


然後這個網站~~~~我覺得更酷XD

你可以選擇你想檔掉哪些國家~~~~~再幫你產生出.htaccess檔~~~

很酷喔~~~

http://www.blockacountry.com/

Apache ~ HTML檔也可以包php語法

一般支援php的apache伺服器~~~他只會讀取php......php3的檔案類型

而這篇要講的就是~~~~~可以讓html檔案類型也可以使用php語法XD


在httpd.conf檔案裡面找這段.....

<IfModule mime_module>

在那標籤底下應該會看到這玩意兒
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3

你只要加上這段
AddType application/x-httpd-php .html

忽忽~~~~~你就會發現你把.php的檔案改成.html他也會正常運作~~~hoho

Apache - 拒絕外部要求~localhost only

前幾天發現我的wamp的首頁............顯示一推做過的網站........

只要我一打開= =...............人家從我IP直接就可以看我做過的網站耶.........

突然覺得這樣不行~~~~所以我就先用PHP把她Deny掉

PHP方法~
在index檔案中上面加入這段程式
if($_SERVER['HTTP_HOST'] != 'localhost')
{
die("FUCK YOU");
}

不用PHP也行~~~可以用Apache


Apache方法~
在.htaccess中打這段語法
Allow from 127.0.0.1
Allow from localhost
Deny from all

-----------------------------------------------------------------------------------------------
PHP的方法結果是
FUCK YOU

Apache方法結果是

Forbidden

You don't have permission to access / on this server.

Apache 重新導向~ Redirect(Rewrite)實作@@

好久沒寫網頁說XD

因為某些原因我給熬想說用這方式~~~這樣我就不用~~同內容但不同檔名的檔案一直複製

好險apache有這功能@@~~~~~~很像cakePHP的運作原理~~~~~~~

但要用之前要把這個打開 ~~~~(前面的#拿掉)

LoadModule rewrite_module modules/mod_rewrite.so

然後,htaccess檔案~~~~~寫成這樣

<ifmodule mod_rewrite.c>
RewriteEngine on
RewriteRule (.*)php$ index.php [L]
</ifmodule>

測試結果~~~管他我打甚麼網誌~~~bitty.php或是ferrari.php都會連到同個檔案index.php

但只限於php結尾= =

一開始我打這樣~~~~~~結果會變成css/main.css這個檔案也被導向到index.php
RewriteRule (.*) index.php [L]

所以後來改成以php結尾~~~~~就正常了

參考資料~~張睪提供的
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
Regular Expression的用法~~我也是上去看才知道$結尾用法= =
http://phi.sinica.edu.tw/aspac/reports/94/94019/ch2.html