heem
1
คือว่า .htaccess ของผมเป็นแบบนี้
Options +FollowSymlinks
RewriteEngine On
## Load CSS File
RewriteRule css/([^/]*)$ css/$1 [NC,L]
RewriteRule images/([^/]*)$ images/$1 [NC,L]
RewriteRule images/([^/]*)/([^/]*)$ images/$1/$2 [NC,L]
## If there are real file or directory
RewriteCond %{REQUEST_FILENAME} -f [NC]
RewriteRule ^ %{REQUEST_FILENAME} [L]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule ^ %{REQUEST_FILENAME} [L]
## Home
RewriteRule ^([^/]*)\.php$ index.php?module=home&action=$1 [L,QSA]
## Other Dir
RewriteRule ^([^/]*)/$ index.php?module=$1&action=index [L,QSA]
RewriteRule ^([^/]*)/([^/]*)\.php$ index.php?module=$1&action=$2 [L,QSA]
ที่ต้องการคือ หาก file หรือ dir มีจริง ก็ให้โหลดขอ้มูลนั้นๆ มาเลย (โดยตรง) หากไม่พบ(ไม่มีจริง) ก็ให้ไปตาม #Home หรือ #Other Dir ตามลำดับ
ทีนี้คือ ลองอัพโหลดแล้วลองเทสบน host จริง ก็ทำงานได้ปกติ
แต่ทีนี้ปัญหาคือว่า พอลองใน localhost (ใช้ Windows) แล้ว มันขึ้น Error 403
You don't have permission to access /D:/AppServ/www/2010/ on this server.
ผมทำ อะไรผิดตรงไหนครับ ช่วยชี้แนะทีนะครับ
ขอบคุณครับ
จากกากฉึกฉามา .htaccess รันได้เฉพาะ Linux นะงับ
heem
3
มันรันได้นะครับ
แต่ติดปัญหาตรง
You don't have permission to access /D:/AppServ/www/2010/ on this server.
เหมือนว่ามันมี / เกินมา อะครับ?
/D:/AppServ/www/2010/
ก็เลยไม่รู้ว่าผิดตรงไหนนะครับ
อันนี้ไม่แน่ใจว่าปัญหาเกิดจากส่วนใด ลองดูการตั้งค่าดูก่อนครับว่าตัว apache ได้เปิด mod_rewrite.so ไว้รึเปล่า
(แต่น่าจะไม่เกี่ยว เพราะถ้าไม่ได้เปิดมันต้องขึ้น error 500) ไล่เช็คทีละส่วนเลยครับ อ่อ ลองไม่ใช้ htaccess ยังเจอ
error 403 อีกรึเปล่าครับ?
ถ้ายังไม่ได้ให้ลองใส่ บรรทัดด้านล่างนี้หลัง RewriteEngine On ดูครับ
ปล. อาจดูเรื่องของ DirectoryIndex อะไรด้วย (ถ้ายังไม่หาย)
RewriteBase /2010/
heem
6
เท่าที่สังเกตนะครับ
จะมีปัญหาตรง
## If there are real file or directory
RewriteCond %{REQUEST_FILENAME} -f [NC]
RewriteRule ^ %{REQUEST_FILENAME} [L]
ปกติผมใช้แค่
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
heem
8
ทีแรกก็ทำแบบนี้แหละครับ แต่เจอปัญหาคือ
(ตามลิงค์นี้มี File / dir อยู่จริงๆ)
http://web/t.php
You don’t have permission to access /D:/AppServ/www/2010/ on this server.
ลองดู path กับให้สิทธิโฟลเดอร์หรือยังครับผม User : iusr_xxxxx
heem
10
ปัญหาตอนนี้ คิดว่าตรง
You don’t have permission to access /D:/AppServ/www/2010/ on this server.
มี / มาก่อน D: ตัวนึงนั่นแหละครับ เลยทำให้ path file มันไม่ถูก (ใช่หรือป่าว) แล้วไอ้ / ที่ว่านี่มาได้ไงท่านใดทราบไหมครับ? (มาจาก ^ หรือ?)
heem
11
คิดไม่ตกเลยครับว่าจะแก้ หรือผิดตรงไหน
ทำต่อไม่ได้ ติดอยู่เลยครับ ><"
ใน httpd.conf ใน <VirtualHost …> ตั้ง
<IfModule mod_rewrite.c>
heem
13
[quote author=Scalopus+ link=topic=24983.msg238794#msg238794 date=1261742717]
ใน httpd.conf ใน <VirtualHost …> ตั้ง
<IfModule mod_rewrite.c>
icez
14
ตั้ง rewrite ผิดเองนี่ครับ
RewriteCond %{REQUEST_FILENAME} -f [NC]
RewriteRule ^ %{REQUEST_FILENAME} [L]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule ^ %{REQUEST_FILENAME} [L]
rewritecond สองบรรทัดนี้ถือว่าอยู่กับคนละ rule กันนะครับ
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
ใช้ดักอย่างนี้ในเงื่อนไขด้านล่างดีกว่าครับ
heem
15
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
## Home
RewriteRule ^([^/]*)\.php$ index.php?module=home&action=$1 [L,QSA]
## Other Dir
RewriteRule ^([^/]*)/$ index.php?module=$1&action=index [L,QSA]
RewriteRule ^([^/]*)/([^/]*)\.php$ index.php?module=$1&action=$2 [L,QSA]
เข้า http://web/t.php
heem
16
ทวนความต้องการอีกนิดนะครับ
- ผมจะให้เข้าเวปโดยถ้าเป็น home (hxxp://web/
icez
17
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Home
RewriteRule ^([^/]*).php$ index.php?module=home&action=$1 [L,QSA]
Other Dir
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/$ index.php?module=$1&action=index [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/])/([^/]).php$ index.php?module=$1&action=$2 [L,QSA]
heem
18
ได้แล้วครับ ขอบคุณครับ
ไม่ทราบจริงๆ ว่ามันต้อง Cond ทุก Ruel เลย