1

I have a .htaccess rewrite that I would like to move to a vhost.conf (I don't want to use .htaccess)

RewriteRule ^(.*?)(test_mod_rewrite) /$1media/plg_jchoptimize/assets/modrewrite.php?q=$2

RewriteRule ^(.*?)(gz|nz)/([^/]+)/([^/]+)/([^/]+)\.(js|css)$  /$1media/plg_jchoptimize/assets/jscss.php?f=$5&type=$6&gz=$2&d=$3&i=$4

Assuming that I have the proper modules enabled and prerequisites met ( RewriteEngine On, etc.), What changes are necessary to get this rule to work within a vhost.conf file?

2

RewriteRules (assuming you have RewriteEngine On also set) work well and pretty much the same in both .htaccess files and in your virtual host configuration. The only main difference is that it works in a per-server context instead of a per-directory in your vhost config, which means that URL matches like "foo" are now "/foo" instead (note the added forward slash at the beginning, this is what most people forget about). Furthermore, the resulting path may, in a per-server context, be a full file system path instead of just a relative URI.

RewriteRule foo.bar baz.abc now becomes RewriteRule /foo.bar baz.abc

The way the system figures out whether you are telling it to use create a rewrite to a file system path or a relative URI is by checking the first bit of the result against the file system. Thus, if you rewrite /foo to /home/foo, and /home exists on your file system, it will be treated as a file system rewrite instead of just a relative URI rewrite.

Assuming you have /home but not /img on your file system, then:

RewriteRule /index.html /home/jane/index.html <-- file system path rewrite (/home exists on file system)

RewriteRule /index.html /img/index.html <-- relative rewrite (/img does not exist on file system, so youdomain/img/index.html is the result)

I hope this answers your question

0

Issue was related to another rewrite rule outside of a block.

For history - this works. Change directory to suit.

<Directory /var/www/site/public_html/media/plg_jchoptimize/assets/>
    RewriteEngine On
    RewriteRule ^(.*?)(test_mod_rewrite) /$1media/plg_jchoptimize/assets/modrewrite.php?q=$2
    RewriteRule ^(.*?)(gz|nz)/([^/]+)/([^/]+)/([^/]+)\.(js|css)$  /$1media/plg_jchoptimize/assets/jscss.php?f=$5&type=$6&gz=$2&d=$3&i=$4
    Require all granted
</Directory>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.