Forum

Need help with Apache's .htaccess

Amar
28 June 2011, 16:26
Hello Hugo

May I ask your help regarding 2 Apache's .htaccess rewrite rules as I am total regex 0. These are ony things keepeng me moving 2 very popular sites to Hiawatha : )

1:
RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.url.ba [NC]
RewriteRule ^(.*)$ http://url.ba/$1 [R=301,L]

RewriteRule ^api\.php /index.php?c=api&m=index&%{QUERY_STRING} [L]
RewriteRule ^contact\.php /index.php?c=contact&m=index&%{QUERY_STRING} [L]
RewriteRule ^([a-zA-Z0-9]{4,25})$ /index.php?c=api&m=check&hash=$1 [L]

RewriteCond $1 !^(index\.php|images|css|script|ZeroClipboard\.swf)
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) / [R=301,L]


2.
RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.img.ba.ba$ [NC]
RewriteRule ^(.*)$ http://img.ba/$1 [R=301,L]

RewriteCond $1 !(\/protected)$
RewriteRule ^(.*)\/protected$ /protected.php?hash=$1 [L]

RewriteCond $1 !(thumb\.php)$
RewriteRule ^(.*)\/thumb$ /thumb.php?hash=$1 [L]

RewriteCond $1 !^(index\.php|thumb\.php|upload\.php|contact\.php|protected\.php|api\.php|password\.php|favicon\.ico|images|css|script)
RewriteRule ^(.*)$ /index.php?hash=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) / [R=301,L]


Thanks a bunch

Hiawatha version: 7.5
Operating System: Debian
Hugo Leisink
28 June 2011, 18:03
Try the following rules and let me know if it works. I think it will need some more tweaking, but it's a start.

1:
Match ^/api\.php(\?.*?) Rewrite /index.php?c=api&m=index&$1
Match ^/contact\.php(\?.*?) Rewrite /index.php?c=contact&m=index&$1
Match ^/([a-zA-Z0-9]{4,25})$ Rewrite /index.php?c=api&m=check&hash=$1

Match ^/(index\.php|images|css|script|ZeroClipboard\.swf) Return
Match ^/(.*)$ Rewrite /index.php/$1


2:
Match ^/protected Skip 1
Match ^/(.*)\/protected$ Rewrite /protected.php?hash=$1

Match /thumb\.php Skip 1
Match ^/(.*)\/thumb$ Rewrite /thumb.php?hash=$1

Match ^/(index\.php|thumb\.php|upload\.php|contact\.php|protected\.php|api\.php|password\.php|favicon\.ico|images|css|script) Return
Match ^/(.*)$ Rewrite /index.php?hash=$1
Amar
28 June 2011, 21:18
Hello Hugo.. Now it's time for me to ask you to edit your hosts file : ). IP address is 78.47.51.44

If I access http://url.ba/index.php it's fine.. Without /index.php I get 404.. If I try to access any link on page ie. /#new or /#popular I get 404 too (but it's like page is displayed for milisecond and than it pops uot 404)
Hugo Leisink
29 June 2011, 18:55
Change the first UrlToolkit rule to this one.
Match ^/api\.php(\?(.*))? Rewrite /index.php?c=api&m=index&$2
Match ^/contact\.php(\?(.*))? Rewrite /index.php?c=contact&m=index&$2
Match ^/([a-zA-Z0-9]{4,25})$ Rewrite /index.php?c=api&m=check&hash=$1

RequestURI isfile Return
Match ^/(images|css|script) Return
Match ^/(.*)$ Rewrite /index.php/$1

Add "EnablePathInfo = yes" to the VirtualHost configuration.
Amar
29 June 2011, 22:12
Hello Hugo.. That seem to worked great : ). Now I will take look at 2nd one and let you know If I have any problems with it..
Amar
30 June 2011, 21:09
Hello Hugo

Just to let you know 2nd rule worked perfectly and now both sites running Hiawatha

Tnx.
Hugo Leisink
30 June 2011, 21:10
Good to hear! Can you tell me what the purpose of the url.ba website is? I don't understand a single word on it. What language is that?
Amar
30 June 2011, 23:00
Bosnian : )

It's short URL service.. only one localized here.. Other site is img.ba which is image sharing site
Hugo Leisink
30 June 2011, 23:02
Oke, nice to have Hiawatha serving a Bosnian website. The first one I know of!
This topic has been closed.