I have a subdirectory within my WP installation called labs. I created a WP page called labs as well. When a user hits mydomain.com/labs/ I want them to load up the WP page. But instead it’s loading up the labs directory listing.

I’ve read a few ways to do this if I want my WP page to have a different name than my directory name, but I don’t really want that. For example, I want to have:

mydomain.com/                <-- WP Root
mydomain.com/labs/           <-- Pretty WP page listing all of my projects
mydomain.com/labs/project1/  <-- raw (i.e. no WP) web app
mydomain.com/labs/project2/  <-- raw (i.e. no WP) web app

Is this possible?

I should also mention that WP is installed in the root of mydomain.com, so /labs/ is both a WP page and a subdirectory that I created manually.


Solution:
I renamed my labs folder to projects and used the following .htaccess.

RewriteEngine On
RewriteCond %{REQUEST_URI} labs/(.+)$
RewriteCond %{REQUEST_URI} !labs/(.+)/$
RewriteRule ^labs/(.+)$ http://mydomain.com/labs/$1/ [L]
RewriteRule ^labs/(.+)$ projects/$1 [L]

I’m a little unclear as to why I had to use

RewriteRule ^labs/(.+)$ http://mydomain.com/labs/$1/ [L]

instead of just

RewriteRule ^labs/(.+)$ labs/$1/ [L]

But when I used the latter it never appended the trailing slash.

5 Answers
5

You’ll need to do some .htaccess-fu to get what you’re proposing to work.

RewriteCond $1 ^/labs/(.+)
RewriteRule ^/labs/(.*)$ /labs-folder/$1 [L]

This isn’t tested yet but it if you put it before the wordpress rules in your htaccess file it will remap urls that begin with /labs/ to /labs-folder/ but not if the url is just “/labs/” on its own.

Let me know if it doesn’t work and I’ll debug it with you.

You can replace “labs-folder” with any folder name you choose but essentially a url like:

http://example.com/labs/project1/

Will really be looking here:

http://example.com/labs-folder/project1/

Leave a Reply

Your email address will not be published. Required fields are marked *