Unable to access httpd.conf

Hi, I’m unable to access httpd.conf.
I’m following the tutorial to make clean uRLs at http://www.sitepoint.com/article/guide-url-rewriting

Please help.

Put your mod_rewrite directives in a file called .htaccess. Place the .htaccess file in the directory where you want the rewriting to take effect (it will also take effect over all sub-directories).
All the best -

Actually, funny that I should find this thread. I’m also trying to do URL rewrites (really simple, just redirecting “/” to “/blog/”) and I’m finding that Apache seems to be completely ignoring my rewrite rules, which I’m putting in .htaccess in the root directory for my website. I’ve read all of the rewrite engine tutorials I can find, and I can’t figure out what I’m doing wrong.

Is it possible that Apache is not configured on my site’s machine (korben) to use mod_rewrite? Or is it necessary to restart Apache as mentioned in the tutorial on SitePoint? (and if so, how on earth do I do that on a shared server?)

I know I could use a simple redirect for this, but redirects take way too long, which is embarassing on the opening page of a website … I’d much rather have the instant redirection of a rewritten URL.


Can you post the rules?

Simon Jessey
Keystone Websites (business site) | si-blog (personal site with affiliate links)

Well, it’d take me forever to list everything I’ve tried – it seems there isn’t a tutorial anywhere that tells me how to do something as simple as what I’m doing. Seems like any discussion on rewriting starts off “ok, say you’ve got this monstrous URL with funky parameters and you want to translate it into this complex directory structure that’s easier to read…”

But anyway, here’s a verbatim copy of my .htaccess file with the last thing I tried, probably my 25th attempt. The +Includes and XBitHack lines were already there, I think some other piece of software I’m using required them.

RewriteEngine on
Options +Includes
XBitHack on
RewriteBase /
#RewriteCond ${REQUEST_URI}  /
RewriteRule ^/$ /blog/ [R]

Are my expectations correct? If it’s going to work, should I expect to see the result next time I try to load the page?

Hmmm. I think that rule is attempting to move the DocumentRoot to /blog/, rather than a basic redirect. That means that /foo.php would also get be redirected to /blog/foo.php, which you don’t want.

This is all voodoo to me. There are a couple of mod_rewrite gurus who wander around here, so hopefully someone will step in.

Simon Jessey
Keystone Websites (business site) | si-blog (personal site with affiliate links)

You’re right, since I also have a gallery at the same site, using the /gallery/ as its path. But at least it’d be a good start, progress in the right direction.

Perhaps I should ask the question again in a new thread, as the subject line of this one isn’t very descriptive…

$ is an anchor; it means the pattern before it should be the last part of the string.
That is, http://example.com/ should redirect to http://example.com/blog/, but http://example.com/gallery/ should not, because /gallery/ does not match ^/$

/gallery/ matches ^/
/gallery/ matches /$
/gallery/ does not match ^/$
– (the single slash in the pattern has to be both at the beginning and the end)

Same effect can be achieved RedirectMatch directive instead of a rewrite rule.

But the RewriteRule cannot use ^/$ to match http://example.com/, because in .htaccess files the path is stripped from the string to begin with; http://example.com/ starts out zero-length, and to match a zero-length string, the pattern is ^$:

#Redirect only / to /blog/ RewriteRule ^$ /blog/ [R]
:cool: Perl / MySQL / HTML CSS

Now that is a great reply. Not only does Atropos7 present a solution, but he also explains how he arrived at it. Give that man a cigar!

Simon Jessey
Keystone Websites (business site) | si-blog (personal site with affiliate links)

Thank you so much for that solution and explanation. I tried it, and it works exactly as I’d hoped. No more waiting at the “you’re being redirected” page!

Why can’t all forums be this helpful?! :o)