[ maddog_srb @ 18.10.2009. 18:33 ] @
Citat:
With mod_rewrite you either shoot yourself in the foot the first time and never use it again or love it for the rest of your life because of its power.

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

Mislim da uvod govori sve. Nije potrebno reci da spadam u ovu prvu grupu, ali tezim da napravim prelaz.

Naime problem je sledeci:
Zelim izmene tipa:
* http://localhost/mysite/variable/value.html => http://localhost/mysite/index.php?variable=value
* http://localhost/mysite/bad-variable/bad-value.html => http://localhost/mysite/index.php?location="error-page.html"
* http://localhost/mysite/ => http://localhost/mysite/index.php?location="home"

Prva dva uslova mi rade, ali poslednji ne.
To sam odradio otprilike ovako:

Code:

RewriteEngine on

# Force one address for a site running on port 80
# NOT TESTED
#RewriteCond %{HTTP_HOST}    !^http://localhost/posv2/ [NC]
#RewriteCond %{HTTP_HOST}    !^$
#RewriteRule ^/(.*)              http://localhost/posv2/$1 [R]

# Home page  - ovaj deo NE radi
RewriteCond %{HTTP_HOST}      !^http://localhost/posv2/ [NC]
RewriteCond %{HTTP_HOST}      !^$
RewriteRule ^(.*)                      http://localhost/posv2/index.php?location=home [R]

# All valid pages - ovaj deo radi
RewriteRule (.*)\/(.*)\.html$        index.php?$1=$2 [L,NC]

# All invalid pages  - ovaj deo radi
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$              index.php?location="$1" [L,QSA]



Problem je sto mi deo za home page ne radi kako treba. Izbaci mi "ponekad" tacnu vrednost za location=home, ali mi svi .css i slike odu u aut.

Neznam da li je uopste, bilo sta u .htaccess fajlu dobro, pa se nadam da ce mi neko strucniji ukazati na propuste. Hvala

[Ovu poruku je menjao maddog_srb dana 18.10.2009. u 19:52 GMT+1]
[ maddog_srb @ 19.10.2009. 15:05 ] @
Da pokusam malo da razjasnim problem...

Struktura direktorijuma je ovakva:

- www
- mojsajt
+ styles
+ images
- pages
+ folder_1
+ folder_2
+ folder_n
= index.php
= error.php
= pages.php

zelim da se celom sadrzaju pristupa preko: http://localhost/mojsajt/index.php?variable=value

Znaci za foldere styles i images ne bi trebalo da se radi rewrite, ali sledeci kod neradi
Code:

RewriteRule \.(css|jpg|png)$ - [L]


pa sam to resio sa sledecim
Code:

RewriteRule styles/(.*)$ styles/$1
RewriteRule images/(.*)$ images/$1


ali onda i kada mi se u adresi pojavi "styles" ili "images" prikazuje nepostojecu stranicu...
cak mi i ovaj deo za valid and invalid pages nekada radi, a nekada nece :o

evo celog .htaccess fajla
Code:

Options +FollowSymLinks
RewriteEngine on

# REDIRECT /folder/index.php to /folder/
RewriteCond %{THE_REQUEST}    ^[A-Z]{3,9}\ /([^/]+/)*index\.(php|html|htm|xhtml)\ HTTP/
RewriteRule ^(([^/]+/)*)index\.(php|html|htm|xhtml)$   http://localhost/posv2/$1 [R=301,L]

# CSS and images
RewriteRule styles/(.*)$          styles/$1
RewriteRule images/(.*)$         images/$1

# Valid pages
RewriteRule ^(.*)\/(.*)\.html$  index.php?$1=$2 [L,NC]

# All invalid pages
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$                       index.php?location=$1 [L]


kada se unese http://localhost/mojsajt/ u $_GET metodi ne postoji "location"
[ ||NeX|| @ 22.10.2009. 10:45 ] @
Otiđi na oficijelnu stranicu od modrewrite-a i tamo imaš forum. Postavi pitanje i u roku minuta će ti odgovoriti.
[ Predrag Supurovic @ 22.10.2009. 16:16 ] @
Ovo...

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


... bi trebalo da stoji na pocetku. Tako ce imati prioritet u odnosu na sva pravila url rewritinga.