.htaccess tutorial

htaccess Elite


Directories That Dont Exist .htaccess Still Interpret?

Ask your mod_rewrite and Redirection questions here, and get answers!

Directories That Dont Exist .htaccess Still Interpret?

New postby waynobweno » 07 Feb 2009 02:48

Hello, I am trying to set up an SEO friendly website that uses htaccess. I have everything working correctly except for one thing.

I want to be able to have depth to my site so that all my pages are not on the same level. I want to be able to silo my content for better optimization.

As is right now, all of my pages are on the root directory of the site. So the-page.html, the-page2.html etc are all on the same directory level such as this:
(Example A)
http://www.mysite.com/the-page.html
http://www.mysite.com/the-page2.html

What I want to be able to so is create URL's like this and add in a virtual directory (this directory doesn't exist) but the SE will think it does:
My URL's look like this: http://www.mysite.com/thedirectory/the-page.html

Can .htaccess work this way? All of my pages are rendered dynamically, so are my URL's. "thedirectory" would just be a trigger I would pull from the database and insert into the URL for better optimization. In direct reflect though, the page would render out just like it would if it were on the first example (A).

Here is my working code. This will take my URL and correctly interpret it: http://www.mysite.com/my-page.html
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]+)\.html$ http://%{HTTP_HOST}/index.php?pagename_id=$1 [L]
ErrorDocument 404 /errorpage.php

I want to be able to have a page like so: http://www.mysite.com/my-directory/my-page.html and still have it render the way that http://www.mysite.com/my-page.html would render. Is this possible.

When I do it right now, I get a 404 page not found error because the directory "my-directory" doesnt exist. What can .htaccess do to fix this.

Thanks for your help!
waynobweno
 
Posts: 1
Joined: 07 Feb 2009 02:37

Return to Redirect or Rewrite Questions