Forum

Help this .htaccess to hiawatha

David
24 March 2018, 14:22
hello,
how to fix this .htaccess please

Options +FollowSymLinks -MultiViews +Indexes
<FilesMatch "\.(htaccess|htpasswd|ini|log|sh|inc|bak|tpl)$">
Order Allow,Deny
Deny from all
</FilesMatch>

# Cache Control
<IfModule mod_headers.c>
<FilesMatch "\.(jpg|jpeg|png|gif|swf|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
</IfModule>

RewriteEngine on
RewriteOptions MaxRedirects=1
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]

# Installer
RewriteRule ^install/?$ install.php [L]

# Static Pages
RewriteRule ^static/([^/]+)/?$ static.php?url=$1 [L]

# Contacts
RewriteRule ^contacts/?$ contact.php [L]

# Directory
RewriteRule ^directory/?$ directory.php [L]
RewriteRule ^directory/([^/]+)/?$ directory.php?view=$1 [L]
RewriteRule ^directory/([^/]+)/([^/]+)/?$ directory.php?view=$1&page=$2 [L]

# Search
RewriteRule ^search/?$ search.php [L]
RewriteRule ^search/hashtag/([^/]+)/?$ search.php?query=$1&hashtag=1 [L]
RewriteRule ^search/([^/]+)/?$ search.php?query=$1&hashtag=0 [L]

# Sign(in|up|out)
RewriteRule ^signin/?$ sign.php?do=in [L]
RewriteRule ^signup/?$ sign.php?do=up [L]
RewriteRule ^signout/?$ sign.php?do=out [L]
RewriteRule ^reset/?$ sign.php?do=reset [L]
RewriteRule ^activation/([^/]+)/([^/]+)/?$ activation.php?id=$1&token=$2 [L]

# Social Logins
RewriteRule ^connect/([^/]+)/?$ connect.php?do=connect&provider=$1 [L]
RewriteRule ^revoke/([^/]+)/?$ connect.php?do=revoke&provider=$1 [L]

# Packages
RewriteRule ^packages/?$ packages.php [L]

# Started
RewriteRule ^started/?$ started.php [L]
RewriteRule ^started/finished?$ started.php?finished=true [L]

# Messages
RewriteRule ^messages/?$ messages.php [L]
RewriteRule ^messages/new?$ messages.php?view=new [L]
RewriteRule ^messages/([^/]+)/?$ messages.php?cid=$1 [L]

# Notifications
RewriteRule ^notifications/?$ notifications.php [L]

# Settings
RewriteRule ^settings/?$ settings.php [L]
RewriteRule ^settings/([^/]+)/?$ settings.php?view=$1 [L]

# Posts & Photos
RewriteRule ^posts/([^/]+)/?$ post.php?post_id=$1 [L]
RewriteRule ^photos/([^/]+)/?$ photo.php?photo_id=$1 [L]

# Saved
RewriteRule ^saved/?$ index.php?view=saved [L]

# People
RewriteRule ^people/?$ people.php [L]
RewriteRule ^people/find/?$ people.php?view=find [L]
RewriteRule ^people/friend_requests/?$ people.php?view=friend_requests [L]
RewriteRule ^people/sent_requests/?$ people.php?view=sent_requests [L]

# Pages
RewriteRule ^pages/?$ pages.php [L]
RewriteRule ^pages/liked/?$ pages.php?view=liked [L]
RewriteRule ^pages/manage/?$ pages.php?view=manage [L]
RewriteRule ^pages/([^/]+)/?$ page.php?username=$1 [L,QSA]
RewriteRule ^pages/([^/]+)/([^/]+)/?$ page.php?username=$1&view=$2 [L]
RewriteRule ^pages/([^/]+)/([^/]+)/([^/]+)/?$ page.php?username=$1&view=$2&id=$3 [L]

# Groups
RewriteRule ^groups/?$ groups.php [L]
RewriteRule ^groups/joined/?$ groups.php?view=joined [L]
RewriteRule ^groups/manage/?$ groups.php?view=manage [L]
RewriteRule ^groups/([^/]+)/?$ group.php?username=$1 [L,QSA]
RewriteRule ^groups/([^/]+)/([^/]+)/?$ group.php?username=$1&view=$2 [L]
RewriteRule ^groups/([^/]+)/([^/]+)/([^/]+)/?$ group.php?username=$1&view=$2&id=$3 [L]

# Events
RewriteRule ^events/?$ events.php [L]
RewriteRule ^events/going/?$ events.php?view=going [L]
RewriteRule ^events/interested/?$ events.php?view=interested [L]
RewriteRule ^events/invited/?$ events.php?view=invited [L]
RewriteRule ^events/manage/?$ events.php?view=manage [L]
RewriteRule ^events/([^/]+)/?$ event.php?event_id=$1 [L,QSA]
RewriteRule ^events/([^/]+)/([^/]+)/?$ event.php?event_id=$1&view=$2 [L]
RewriteRule ^events/([^/]+)/([^/]+)/([^/]+)/?$ event.php?event_id=$1&view=$2&id=$3 [L]

# Blogs
RewriteRule ^articles/?$ index.php?view=articles [L]
RewriteRule ^blogs/?$ blogs.php [L]
RewriteRule ^blogs/new/?$ blogs.php?view=new [L]
RewriteRule ^blogs/edit/([^/]+)/?$ blogs.php?view=edit&post_id=$1 [L]
RewriteRule ^blogs/([^/]+)/([^/]+)/?$ blogs.php?view=article&post_id=$1 [L]

# Market
RewriteRule ^products/?$ index.php?view=products [L]
RewriteRule ^market/?$ market.php [L]
RewriteRule ^market/search/?$ market.php?view=search [L]
RewriteRule ^market/search/([^/]+)/?$ market.php?view=search&query=$1 [L]
RewriteRule ^market/search/([^/]+)/([^/]+)/?$ market.php?view=search&query=$1&page=$2 [L]
RewriteRule ^market/category/([^/]+)/?$ market.php?view=category&category_id=$1 [L]
RewriteRule ^market/category/([^/]+)/([^/]+)/?$ market.php?view=category&category_id=$1&category_url=$2 [L]
RewriteRule ^market/category/([^/]+)/([^/]+)/([^/]+)/?$ market.php?view=category&category_id=$1&category_url=$2&page=$3 [L]
RewriteRule ^market/([^/]+)/?$ market.php?page=$1 [L]

# Games
RewriteRule ^games/?$ games.php [L]
RewriteRule ^games/played/?$ games.php?view=played [L]
RewriteRule ^games/([^/]+)/?$ game.php?id=$1 [L]

# Admin Panel
RewriteRule ^admincp/?$ admin.php [L]
RewriteRule ^admincp/([^/]+)/?$ admin.php?view=$1 [L]
RewriteRule ^admincp/([^/]+)/([^/]+)/?$ admin.php?view=$1&sub_view=$2 [L]
RewriteRule ^admincp/([^/]+)/([^/]+)/([^/]+)/?$ admin.php?view=$1&sub_view=$2&id=$3 [L]

# Profile
RewriteRule ^([^/]+)/?$ profile.php?username=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ profile.php?username=$1&view=$2 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ profile.php?username=$1&view=$2&id=$3 [L]
Hugo Leisink
25 March 2018, 21:20
How to fix: contact the developers of the piece of software that requires this rewrite rule and tell them that this rewriting does not belong in the configuration of a webserver, but in the application itself.
Rimas
26 March 2018, 18:55
I'm not using Hiawatha myself, so take this advice with a grain of salt, but you may want to try the following:

[ol]
  • Change this block:
    Options +FollowSymLinks -MultiViews +Indexes
    <FilesMatch "\.(htaccess|htpasswd|ini|log|sh|inc|bak|tpl)$">
    Order Allow,Deny
    Deny from all
    </FilesMatch>

    to this:
    Match \.(htaccss|htpasswd|ini|log|sh|inc|bak|tpl)$ DenyAccess


  • then this block:
    RewriteEngine on
    RewriteOptions MaxRedirects=1
    RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
    RewriteCond %{REQUEST_FILENAME} -d [NC]
    RewriteRule .* - [L]

    to this:
    RequestURI exists Return

  • then change each RewriteRule line like this:
    RewriteRule ^install/?$ install.php [L]

    to a line like this:
    Match ^install/?$ Rewrite install.php

    In other words, replace "RewriteRule" with "Match", insert the word "Rewrite" between the components of the rewrite rule, and remove "[L]" at the end of each the line.
    [/list]

    With all that done, all that remains is this block:
    <IfModule mod_headers.c>
    <FilesMatch "\.(jpg|jpeg|png|gif|swf|css|js)$">
    Header set Cache-Control "max-age=604800, public"
    </FilesMatch>
    </IfModule>

    For it, "CustomHeaderClient" directive might work, but I'm not sure how to limit it to the listed file types only. Perhaps Hugo or someone else will be willing to help you out with that bit, but even if not, you still have options available to you like using a different HTTP server, or simply not sending that particular header for these particular types of files.
    Hope this helps, cheers!
  • Hugo Leisink
    26 March 2018, 19:06
    The general rule is more like.
    RewriteRule ^hello hello.php [L]

    to
    Match ^/hello Rewrite /hello.php

    Pay attention to the slashes.
    Nicolas
    26 March 2018, 20:21
    Hello,

    For the Cache-Control part, you can ask Hiawatha to set the correct header with the ExpirePeriod parameter :

    https://www.hiawatha-webserver.org/manpages/hiawatha/#lbAJ

    Directory {
    DirectoryID = cache-control
    Path = /
    Extensions = gif, png, jpg, jpeg, js, swf, css
    ExpirePeriod = 1 week, public
    }

    You can fine tune the path, but I don't know if it's really useful. I'm also not sure why I have jpg and jpeg in my configuration, but you can test if you need both or if either is fine (I don't remember if I did or not before using both).

    After that, you'll need to use the UseDirectory parameter for your virtual host :

    UseDirectory = cache-control
    This topic has been closed.