.htaccess exclude subfolders from urls

Please support our Site Layout and Usability advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Aug 2009
Posts: 94
Reputation: valonesal is an unknown quantity at this point 
Solved Threads: 2
valonesal's Avatar
valonesal valonesal is offline Offline
Junior Poster in Training

.htaccess exclude subfolders from urls

 
0
  #1
Sep 5th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: .htaccess exclude subfolders from urls

 
0
  #2
Sep 5th, 2009
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/
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 94
Reputation: valonesal is an unknown quantity at this point 
Solved Threads: 2
valonesal's Avatar
valonesal valonesal is offline Offline
Junior Poster in Training

Re: .htaccess exclude subfolders from urls

 
0
  #3
Sep 5th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: .htaccess exclude subfolders from urls

 
0
  #4
Sep 5th, 2009
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.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 94
Reputation: valonesal is an unknown quantity at this point 
Solved Threads: 2
valonesal's Avatar
valonesal valonesal is offline Offline
Junior Poster in Training

Re: .htaccess exclude subfolders from urls

 
0
  #5
Sep 5th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 94
Reputation: valonesal is an unknown quantity at this point 
Solved Threads: 2
valonesal's Avatar
valonesal valonesal is offline Offline
Junior Poster in Training

Re: .htaccess exclude subfolders from urls

 
0
  #6
Sep 5th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 94
Reputation: valonesal is an unknown quantity at this point 
Solved Threads: 2
valonesal's Avatar
valonesal valonesal is offline Offline
Junior Poster in Training

Re: .htaccess exclude subfolders from urls

 
0
  #7
Sep 6th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Site Layout and Usability Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC