943,614 Members | Top Members by Rank

Ad:
Sep 5th, 2009
0

.htaccess exclude subfolders from urls

Expand Post »
ok i have been working on this for 2 days now here is what im trying to do.

I have urls that look like this www.mysite.com/folder/folder/folder/file.php

What I would like the url to look like the url to look like is www.mysite.com/file.php

I know this can be done with .htacces i just cant figure out how.

If anyone knows how please share, thanks in advance.
Reputation Points: 10
Solved Threads: 2
Junior Poster
valonesal is offline Offline
120 posts
since Aug 2009
Sep 5th, 2009
0

Re: .htaccess exclude subfolders from urls

You will want rewrites to do this.

This will be fairly simple if the 'folder/folder/folder' is always the same, but if you have alot of sub directories then you will need more than just /file.php in the final URL

Take a look at http://www.sitepoint.com/article/guide-url-rewriting/
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
Sep 5th, 2009
0

Re: .htaccess exclude subfolders from urls

Yes I will have more that one subfolder, outside of folder,folder,folder

As I mentioned I have worked on this for days now with no clue anything you can provide is appreciated.
Reputation Points: 10
Solved Threads: 2
Junior Poster
valonesal is offline Offline
120 posts
since Aug 2009
Sep 5th, 2009
0

Re: .htaccess exclude subfolders from urls

URL rewrites are good for translating set patterns, for example:
www.site.com/products.php?catagory=1&product=32&viewmode=2

to:
www.site.com/products/cat1/item32/2

But if you are using unknown folder structures or varying structures, then it will not be suitable unless you have numerous (and probably complex) rewrite rules.
Also, if you want all files to translate to site.com/file.php then you will need to make sure that every single file has a unique name.

ReWrites are best used for SEO, to the end user they make little difference.
Last edited by Will Gresham; Sep 5th, 2009 at 8:20 pm.
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
Sep 5th, 2009
0

Re: .htaccess exclude subfolders from urls

Basically Im just using it to mask or remove the subfolders from the url so maybe it would be easier to just subtract certain folders from urls.

So rather than changing file names can we just subtract folder1,folder2 from all urls on my site? But still display page.

Is this possible if so how?
Reputation Points: 10
Solved Threads: 2
Junior Poster
valonesal is offline Offline
120 posts
since Aug 2009
Sep 5th, 2009
0

Re: .htaccess exclude subfolders from urls

Could I use something like this for multiple files?

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/free($|/)
RewriteRule ^.*$ /paid/index.html [L]

Or This

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(folder1|folder2|folder3).*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./folder1/folder2/index.php [L]
Last edited by valonesal; Sep 5th, 2009 at 8:40 pm.
Reputation Points: 10
Solved Threads: 2
Junior Poster
valonesal is offline Offline
120 posts
since Aug 2009
Sep 6th, 2009
0

Re: .htaccess exclude subfolders from urls

Ok here is what I figured out, if I use

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/free($|/)
RewriteRule ^.*$ /paid/index.html [L]

and repeat the

RewriteCond %{REQUEST_URI} ^/free($|/)
RewriteRule ^.*$ /paid/index.html [L]

i can mask unlimited folders. If anyone has a better way please let me know.
Reputation Points: 10
Solved Threads: 2
Junior Poster
valonesal is offline Offline
120 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Site Layout and Usability Forum Timeline: Search Box
Next Thread in Site Layout and Usability Forum Timeline: Beginners Guide To Creating Database Driven Website





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC