Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I don't seem to be able to do the following in my .htaccess I have my script in a subfolder inside my root directory, let's call it "ecommerce", and inside that subfolder I have my .htaccess. Am trying to make going to a certain subfolder inside "ecommerce" load a certain page within the 2nd subfolder, let's called it "shirts".

Here is my code:

RewriteEngine On
RewriteRule ^ecommerce/shirts/$ /ecommerce/shirts/shirts.php

Here are the address/locations of the the files and folders:

localhost/ecommerce/.htaccess
localhost/ecommerce/shirts/shirts.php

What am trying to do is, if I open

localhost/ecommerce/shirts/

I'll get access to my shirts.php inside, instead of the folder directory. Ofc I made sure that I have mod-writing enabled on my Apache server. Thanks in advance for you help.

share|improve this question

migrated from stackoverflow.com Mar 29 '13 at 9:45

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 1 down vote accepted

When you have a .htaccess in a sub folder, Apache strips the directory prefix from the request URL. Therefore, the RewriteRule pattern must not include the directory prefix

RewriteEngine On
RewriteRule ^shirts/$ /ecommerce/shirts/shirts.php
share|improve this answer
    
I tried doing that, but I got the following: Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 –  Khaled Mar 27 '13 at 23:16
    
@Khaled Then you have no example.php in the example-folder2 directory. I tested this locally and it works as intended. Please see updated answer. –  Olaf Dietsche Mar 27 '13 at 23:24
    
I will re edit my original post, to include some data that might help and clear the confusion am causing here. ^^ –  Khaled Mar 27 '13 at 23:25
    
It has been updated. –  Khaled Mar 27 '13 at 23:50
    
@Khaled Then the first rule works. –  Olaf Dietsche Mar 28 '13 at 0:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.