[Pro] Need htaccess to rewrite subdirectory

Hey Everyone,

We are having an issue with our htaccess file. Our goal is to get the pages in a subdirectory to be viewed in the URL as if it were up a level. For example:

  • Our files are located in :

/folder/subfolder/index.php

Currently we have the following in our htaccess:

RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET /([^. ]+.)+php(?[^ ]*)? HTTP
RewriteRule ^(.+).php$ http://www.domain.com/subfolder/$1 [R=301,L]

For the most part our htaccess is doing it’s job. The only issue we are having is that it is stripping the php extensions off of all our pages. We need the extensions to remain there for technical reasons.

How do we stop it from excluding our extensions? Are we going about this correctly or is there a better way of accomplishing this. Any kind of help would be greatly appreciated.

Thanks,
Bernard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

This works fine for me:

# Redirect old file path to new file path
Redirect /folder/subfolder/index.php http://domain.com/subfolder/index.php

Todd
http://xiiro.com


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hey Todd,

Thanks for the response. It’s not working for us. I could be wrong but I think it is due to the fact that we are not really wanting to redirect users, we want the path to be “masked”. So it looks like it is one directory deep when in actuality it is two directories deep. Our files will always be two directories deep.

Please let me know if I am missing something here.

Thanks, Bernard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Ah, I see. Off the top of my head I’m not sure how to pull that off. I’ll have to look around.

Todd

Thanks for the response. It’s not working for us. I could be wrong but I think it is due to the fact that we are not really wanting to redirect users, we want the path to be “masked”. So it looks like it is one directory deep when in actuality it is two directories deep. Our files will always be two directories deep.

Please let me know if I am missing something here.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I don’t think you can do that entirely with .htaccess. What you can do is create a new subdomain for that folder, and redirect users to the subdomain when they try to navigate into it from the parent folder. So you might go from

http://example.com/test

to

http://test.example.com

and anyone who went into the former would be 301 redirected into the latter.

This brings me to another question: is there a specific reason why that subfolder isn’t where you want the URL to make it appear to be? Can’t you just move that folder?

Walter

On Apr 24, 2013, at 3:42 PM, TeamSDA wrote:

Hey Todd,

Thanks for the response. It’s not working for us. I could be wrong but I think it is due to the fact that we are not really wanting to redirect users, we want the path to be “masked”. So it looks like it is one directory deep when in actuality it is two directories deep. Our files will always be two directories deep.

Please let me know if I am missing something here.

Thanks, Bernard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hey Walt,

Without getting into a huge discussion, yes there are technical limitations to why we can’t have it live on that top level. It has to do with the way our hosting provider has us set up.

In regards to your suggestion, we wouldn’t want it to be a subdomain but if we were to even use the subdomain (which we wouldn’t), the problem is that:

http://test.example.com/page.html

Could be also visited at

http://www.example.com/test/page.html

This passiveness is what we are trying to restrict. Basically the htaccess markup I have represented at the top of this post is doing exactly what we want it to do. It is force rewriting all PHP pages within

/folder/subfolder

to

/subfolder

The only quarrel we have with it is that it is removing the .php extensions off of our pages. Keep in mind that we got this markup off of a form post so someone asked for these extensions to be removed and rewritten. We just want to strip off whatever is forcing the extensions to be removed. Not sure if this will help but the link to that forum post is here:

Thanks for the help, Bernard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Apr 24, 2013, at 5:21 PM, TeamSDA wrote:

Hey Walt,

Without getting into a huge discussion, yes there are technical limitations to why we can’t have it live on that top level. It has to do with the way our hosting provider has us set up.

In regards to your suggestion, we wouldn’t want it to be a subdomain but if we were to even use the subdomain (which we wouldn’t), the problem is that:

http://test.example.com/page.html

Could be also visited at

http://www.example.com/test/page.html

This passiveness is what we are trying to restrict. Basically the htaccess markup I have represented at the top of this post is doing exactly what we want it to do. It is force rewriting all PHP pages within

/folder/subfolder

to

/subfolder

The only quarrel we have with it is that it is removing the .php extensions off of our pages. Keep in mind that we got this markup off of a form post so someone asked for these extensions to be removed and rewritten. We just want to strip off whatever is forcing the extensions to be removed. Not sure if this will help but the link to that forum post is here:
Rewriting Sub-Folder name using .htaccess - Apache Web Server forum at WebmasterWorld - WebmasterWorld

Well your capture (the part in the parentheses) is not including the .php, so that’s why it’s not being put into the $1 variable. You have two options:

RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET /([^. ]+.)+php(?[^ ]*)? HTTP
RewriteRule ^(.+).php$ http://www.domain.com/subfolder/$1.php [R=301,L]
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET /([^. ]+.)+php(?[^ ]*)? HTTP
RewriteRule ^(.+.php)$ http://www.domain.com/subfolder/$1 [R=301,L]

See if either of those work for you.

Walter

Thanks for the help, Bernard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hey Walt,

Thanks for the response. In a little while here, I’m going to contact you offline. What you recommended makes perfect sense to work but it’s still giving us an issue.

I think this requires some detailed explanation of our file structure and htaccess settings so I will send you that in an email. Thanks again for your help on the matter.

Thanks,
Bernard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options