Convert web.config to Caddyfile

(Joshua Griffith) #1

For strange reasons I won’t go into much detail on, I’m looking to run vBulletin on Caddy. I’ll try to summarise by saying I intend to run multiple webapps on the server, and as part of a migration away from vBulletin I’d like to run it using Caddy.

I have both the htaccess and the web.config file, and I’m trying to do conditional rewrites, but I suspect there is more I need to do, and I don’t even know how to do this. If anyone could advise that’d be great… Here’s a dump of web.config:

<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is to support redirection in IIS.
This file is harmless if you are running under Apache -->
				<clear /> <!-- reset other rewrite rules -->
				<rule name="Css" stopProcessing="true">
					<match url="^css.php$" ignoreCase="false" />
					<action type="Rewrite" url="core/css.php" />

				<rule name="Installer" stopProcessing="true">
					<match url="^install/" ignoreCase="true" />
					<action type="Rewrite" url="core/install/" />

				<rule name="Main Redirect" stopProcessing="true">
					<match url="^(.*)$" ignoreCase="false" />
					<conditions logicalGrouping="MatchAll">
						<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
						<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />

					<action type="Rewrite" url="index.php?routestring={R:1}" />

				<rule name="Admincp" stopProcessing="true">
					<match url="^(admincp/)$" ignoreCase="false" />
					<action type="Rewrite" url="index.php?routestring={R:1}" />

The htaccess file looks a bit more complex, I’m not sure how much of it is actually essential, though…

<IfModule mod_rewrite.c>
	RewriteEngine On

	# In some cases where you have other mod_rewrite rules, you may need to remove the 
	# comment on the following RewriteBase line and change it to match your folder name. 
	# This resets the other mod_rewrite rules for just this directory
	# If your site was, the setting would be /forum/
	#RewriteBase /

	# Send css calls directly to the correct file VBV-7807
	RewriteRule ^css.php$ core/css.php [NC,L]

	# Redirect old install path to core.
	RewriteRule ^install/ core/install/ [NC,L]

	# Main Redirect
	RewriteCond %{REQUEST_URI} !\.(gif|jpg|jpeg|png|css)$
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^(.*)$ index.php?routestring=$1 [L,QSA]

	# Because admincp is an actual directory.
	RewriteRule ^(admincp/)$ index.php?routestring=$1 [L,QSA]


<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE application/atom+xml \
                          text/javascript \
                          application/x-javascript \
                          application/javascript \
                          application/json \
                          application/rss+xml \
                          application/ \
                          application/x-font-ttf \
                          application/xhtml+xml \
                          application/xml \
                          font/opentype \
                          image/svg+xml \
                          image/x-icon \
                          text/css \
                          text/html \
                          text/plain \
                          text/x-component \

<IfModule mod_expires.c>
	ExpiresActive On
	ExpiresByType application/x-javascript A1209600
	ExpiresByType text/javascript A1209600
	ExpiresByType application/javascript A1209600
	ExpiresByType text/css A31536000
	ExpiresByType image/x-icon A2592000
	ExpiresByType image/icon A2592000
	ExpiresByType application/x-ico A2592000
	ExpiresByType application/ico A2592000
	ExpiresByType image/gif A2592000
	ExpiresByType image/jpeg A1209600
	ExpiresByType image/jpg A1209600
	ExpiresByType image/png A1209600
	ExpiresByType application/x-shockwave-flash A1209600
	ExpiresByType font/ttf A2592000
	ExpiresByType font/otf A2592000
	ExpiresByType font/x-woff A2592000
	ExpiresByType image/svg+xml A2592000
	ExpiresByType font/truetype A2592000
	ExpiresByType font/opentype A2592000
	ExpiresByType application/x-font-woff A2592000
	ExpiresByType application/ A2592000

<IfModule mod_headers.c>
    Header set Connection keep-alive
	<filesmatch "\.(ico|flv|gif|swf|eot|woff|otf|ttf|svg)$">
		Header set Cache-Control "max-age=2592000, public"
	<filesmatch "\.(jpg|jpeg|png)$">
		Header set Cache-Control "max-age=1209600, public"
	<filesmatch "\.(eot|woff|otf|ttf|svg)$">
		Header set Cache-Control "max-age=2592000, public"
	# css and js should use private for proxy caching
	<filesmatch "\.(css)$">
		Header set Cache-Control "max-age=31536000, private"
	<filesmatch "\.(js)$">
		Header set Cache-Control "max-age=1209600, private"

So far, I’ve just about managed to fix the CSS with the following rewrite:

rewrite {
    r css.php
    to core/css.php

But I still have a long way to go, and I don’t even know if/why this might (not) work.

Revisiting a closed topic. Web.Config to Caddy file
(Matthew Fay) #2

This is all more-or-less doable, I think. You’ll need to be a bit handy, though, because I can see it requiring a bit of experimentation and troubleshooting.

Let me take a crack at that .htaccess. You’re on the right track with that rewrite, but you can be a tad more precise, I think (and avoid going anywhere near a regex, even if there’s no actual regular expression in it).

The following is done quickly by hand and completely untested.

# Send css calls directly to the correct file VBV-7807
rewrite /css.php /core/css.php

# Redirect old install path to core.
rewrite /install {
    to /core/install

# Main Redirect
rewrite {
    ext !gif !jpg !jpeg !png !css
    to {path} {path}/ index.php?routestring={uri}

# Because admincp is an actual directory.
rewrite /admincp {

# <IfModule mod_deflate.c> section
gzip # Ha ha.

# <IfModule mod_expires.c> section
# Requires third-party plugin
expires {
    match .js$ 14d # 1209600 = 14 days
    match .css$ 1y # 31536000 = 365 days - wow, seems a little long for CSS
    match .(gif|jpg|jpeg|png|ttf|otf|woff|svg)$ 1m # 2592000 = 30 days

Didn’t bother with the <IfModule mod_headers.c> section, looks like just a bunch of cache control, should be handled by expires if you use it.

1 Like
(Joshua Griffith) #3

Thanks, I will have a crack at it shortly and let you know how I get on - busy times right now :slight_smile:

(system) closed #4

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.