Forum

.htaccess modrewrite to hiawata rules

GentZu
24 November 2014, 09:16
Options -Indexes
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
## Redirect from non-www to www
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## Redirect from www to non-www
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

## Redirect from non-www to www and http to https
RewriteCond !{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

## Redirect index.php to root domain
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]

RewriteRule ^p/(.*).html$ p.php?pages=$1 [L]
RewriteRule ^search/([0-9]+)/(.*)/mp3.html$ s.php?type=a&p=$1&q=$2 [L]
RewriteRule ^search/(.*)/mp3.html$ s.php?type=a&q=$1 [L]

# Abuse Agent Blocking
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Bolt\ 0 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ZyBorg [NC]
RewriteRule ^.* - [F,L]
# Abuse bot blocking rule end
</IfModule>

<FilesMatch "cnfg.php|direct.php|footer.php|header.php|sidebar.php|recaptchalib.php">
Order allow,deny
Deny from all
</FilesMatch>

please help me how to httaccees functions work on hiawatha
thanks

Hiawatha version: hiawatha 9.8.0
Operating System: Centos 6.6
Hugo Leisink
24 November 2014, 09:59
## Redirect from non-www to www
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## Redirect from www to non-www
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

## Redirect from non-www to www and http to https
RewriteCond !{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Take a look at the EnforceFirstHostname and RequireSSL options for this.

UrlToolkit {
ToolkitID = my_rule

Header User-Agent BlackWidow DenyAccess
Header User-Agent Bolt DenyAccess
Header ZyBorg DenyAccess

Match ^/p/(.*).html$ Rewrite /p.php?pages=$1
Match ^/search/([0-9]+)/(.*)/mp3.html$ Rewrite /s.php?type=a&p=$1&q=$2
Match ^/search/(.*)/mp3.html$ Rewrite /s.php?type=a&q=$1

Match ^/(.*)index.php$ Rewrite /$1
}


Note that I haven't tested this. It might contain some errors. I also have no idea what THE_REQUEST in "RewriteCond %{THE_REQUEST} ^.*/index\.php" means, so I have ignored that line.
GentZu
24 November 2014, 11:44
why if I make ToolkitID can not be restarted?
Hugo Leisink
24 November 2014, 11:50
ToolkitID missing? I've added it to the rule above.
GentZu
24 November 2014, 12:13
#service hiawatha restart
Stopping Hiawatha web server: [FAILED]
Starting Hiawatha web server: Syntax error in /opt/configs/hiawatha/conf/toolkits/my_rule.conf on line 6.
[FAILED]
GentZu
24 November 2014, 12:44
ok is fine, there was a little mistake...
and how to force www and https?
Hugo Leisink
24 November 2014, 15:48
See first remark in my first reply.
This topic has been closed.