Forum Moderators: phranque

Message Too Old, No Replies

From domain htaccess code to the main httpd conf file

How to translate?

         

craig1972

1:14 pm on Feb 1, 2009 (gmt 0)

10+ Year Member



Hi.

I have a root server, and many domains working from it.

In one of my domains, I am using Wordpress. For their "permalinks" they have this kind of htaccess code which I am supposed to put into the wordpress installation directory (which is /html/wordpress on my domain's public_html) --


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /html/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /html/wordpress/index.php [L]
</IfModule>

I would like to take this into the main httpd.conf file, but when I put this above directive into the VirtualHost entry of this domain, I get this error:


yntax error on line 1464 of /usr/local/apache/conf/httpd.conf:
RewriteBase: only valid in per-directory config files

What is the best way to convert this into rewrite instructions for the main Apache config file? Sorry, I searched this forum but couldnt come up with a similar question. I did find out that "!-f" and the "!-d" in the code above mean that we should leave directories alone and just serve the files from an index file.

Appreciate any ideas or advice. Thanks!

jdMorgan

7:23 pm on Feb 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because this can be affected by other config factors, this is just a guess. If it doesn't work, look at the server error log and tweak the "filepath builder" elements in these two RewriteConds so that the server is testing the correct physical filepath for file- and directory-exists.

RewriteCond %{DOCUMENT_ROOT}/html/wordpress%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}/html/wordpress%{REQUEST_URI} !-d
RewriteRule . /html/wordpress/index.php [L]

Since the resulting built-up path can't be seen, it's sometimes helpful to temporarily change the rule to a redirect, and put the built-up-path in a 'fake' query string, the only purpose of which is to display it in your browser address bar so you can see it. Something like:

RewriteRule ^test-path-builder http://www.example.com/html/wordpress/index.php?tested-filepath=%{DOCUMENT_ROOT}/html/wordpress%{REQUEST_URI} [R=301,L]

I put "test-path-builder" in this temporary rule pattern so that you can request "test-path-builder" from and see the rule's output, while not interfering with the normal operation of your server while testing this.

You also don't need the <IfModule> container unless you want this code to fail silently on servers without mod_rewrite installed.

Jim

craig1972

7:53 pm on Feb 1, 2009 (gmt 0)

10+ Year Member



Wow, you're a rock start jdmorgan. THANKS so much. It works! Hope this helps someone else too. Amazing.

craig1972

8:07 pm on Feb 1, 2009 (gmt 0)

10+ Year Member



Ok. Celebrated too soon :)

One problem. I want this condition to take over ONLY when "/html/wordpress" is in the URI. But right now, while this was working, the rule somehow took over "/html" as well!

Is there any way to make sure that "/html/" remains what it is, and the only time the above rule takes over is when there is "/html/support" in the URI?

For example:


RewriteRule ^/html/[b](^[(wordpress)]*)[/b]$ /html/$1 [L]
RewriteCond %{DOCUMENT_ROOT}/html/wordpress%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}/html/wordpress%{REQUEST_URI} !-d
RewriteRule . /html/wordpress/index.php [L]

The item in bold is what I don't know how to write. How should I check for any word "other than wordpress"? Would this work anyway?

jdMorgan

8:17 pm on Feb 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{DOCUMENT_ROOT}/html/wordpress%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}/html/wordpress%{REQUEST_URI} !-d
RewriteRule ^/html/wordpress/. /html/wordpress/index.php [L]

Jim

craig1972

11:50 pm on Feb 1, 2009 (gmt 0)

10+ Year Member



Woo hoo. Immaculate. Thanks mate!