How Do I Eliminate Sub Folder From URL

New to mod_rewrite? This is a good place to start.

How Do I Eliminate Sub Folder From URL

Postby helpvid » Thu Oct 08, 2009 2:39 pm

Guy's at my website http://www.helpvid.net to tidy things up I created a (tutorials) folder, in this folder there are several other folders (dreamweaver) (photoshop) (flash) ect and all my .html files are in there respective folders.

Now if someone wanted to view a dreamweaver tutorial named div tags the URL reads http://www.helpvid.net/tutorials/dreamw ... ivtag.html

As you can see the tutorials and dreamweaver folders in which the divtag.html is storred appears in the URL.

I want the URL to read

http://www.helpvid.net/divtag.html

So my question is how do I eliminate the folders from appearing in the URL ?

I have some knowledge of .htaccess as I edited that so the www. would appear.

I have no experience of mod_rewrite so you will need to let me know where to place the desired code, inside the .htaccess file. Or do I create a new file called mod_rewrite and put the code in there.

Thank you for taking the time to read this.
Mark
helpvid
 
Posts: 15
Joined: Thu Oct 08, 2009 2:17 pm

Postby richardk » Fri Oct 09, 2009 8:00 am

Why??

So my question is how do I eliminate the folders from appearing in the URL ?

You would have to check if the requested (.html) file existed in each of the sub directories. The first to be found would be shown, you couldn't have two with the same name.

I have no experience of mod_rewrite so you will need to let me know where to place the desired code, inside the .htaccess file. Or do I create a new file called mod_rewrite and put the code in there.

The mod_rewrite would go in a .htaccess file, in this case in your document root.

I have some knowledge of .htaccess as I edited that so the www. would appear.

You used mod_rewrite (RewriteCond and RewriteRule) for that, right? It is included in the below mod_rewrite so you can remove your current code.


Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Force www.helpvid.net
RewriteCond %{HTTP_HOST} !^www\.helpvid\.net$ [NC]
RewriteRule .* http://www.helpvid.net%{REQUEST_URI} [R=301,L]

# Check if the file exists in /tutorials/dreamweaver.
RewriteCond %{DOCUMENT_ROOT}/tutorials/dreamweaver/$0 -f
RewriteRule ^[^/]+\.html$ /tutorials/dreamweaver/$0 [QSA,L]

# Check if the file exists in /tutorials/photoshop.
RewriteCond %{DOCUMENT_ROOT}/tutorials/photoshop/$0 -f
RewriteRule ^[^/]+\.html$ /tutorials/photoshop/$0 [QSA,L]

# Check if the file exists in /tutorials/flash.
RewriteCond %{DOCUMENT_ROOT}/tutorials/flash/$0 -f
RewriteRule ^[^/]+\.html$ /tutorials/flash/$0 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby helpvid » Fri Oct 09, 2009 9:15 am

I put the code bellow you provided into my .htaccess file but to no avail, the URL is still reading http://www.helpvid.net/tutorials/dreamw ... ained.html

As you can see the tutorial folder and the dreamweaver sub floder are still appearing. I will say it's the first time I have tried this without messing something up. I have been given all types of code and it usually breaks all the links with a 500 error appearing. So although nothing with your code worked it did not mess anything so I guess we are on the right track now. Any other ideas....????

Options +FollowSymLinks

RewriteEngine On

# Force www.helpvid.net
RewriteCond %{HTTP_HOST} !^www\.helpvid\.net$ [NC]
RewriteRule .* http://www.helpvid.net%{REQUEST_URI} [R=301,L]

# Check if the file exists in /tutorials/dreamweaver.
RewriteCond %{DOCUMENT_ROOT}/tutorials/dreamweaver/$0 -f
RewriteRule ^[^/]+\.html$ /tutorials/dreamweaver/$0 [QSA,L]

# Check if the file exists in /tutorials/photoshop.
RewriteCond %{DOCUMENT_ROOT}/tutorials/photoshop/$0 -f
RewriteRule ^[^/]+\.html$ /tutorials/photoshop/$0 [QSA,L]

# Check if the file exists in /tutorials/flash.
RewriteCond %{DOCUMENT_ROOT}/tutorials/flash/$0 -f
RewriteRule ^[^/]+\.html$ /tutorials/flash/$0 [QSA,L]
helpvid
 
Posts: 15
Joined: Thu Oct 08, 2009 2:17 pm

Postby helpvid » Fri Oct 09, 2009 9:31 am

Is there anything in the code I have forgot to change or alter?
helpvid
 
Posts: 15
Joined: Thu Oct 08, 2009 2:17 pm

Postby richardk » Fri Oct 09, 2009 9:35 am

It's working, visit /CssDivTagsExplained.html. Mod_rewrite does not change the links in the HTML, it works on the incoming browser requests only.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby helpvid » Fri Oct 09, 2009 9:52 am

Yes I see what you mean, when I hand type helpvid.net//CssDivTagsExplained.html it works and gose to the tutorial. However when I go to the website and click on that tutorial the folders still appear in the URL.

What do you mean by, it works on the incoming browser requests only.

Does that mean it will appear as I want it to look from your end, even when you are clicking the links at the website/

Or is this something else I need to learn lol
helpvid
 
Posts: 15
Joined: Thu Oct 08, 2009 2:17 pm

Postby richardk » Fri Oct 09, 2009 12:41 pm

Perhaps i shoudl have phrased it, "incoming (in to the server) requests from the browser". Ie. it only works when there is a request to the server (you click a link or type a URL), not on the response (the outputted HMTL).

You have to edit your HTML so the links are /CssDivTagsExplained.html not /tutorials/dreamweaver/CssDivTagsExplained.html.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby helpvid » Fri Oct 09, 2009 1:09 pm

Confused no path in the HTML file. In dreamweaver the link appears in the HTML properties panel like so /CssDivTagsExplained.html
helpvid
 
Posts: 15
Joined: Thu Oct 08, 2009 2:17 pm

Postby richardk » Fri Oct 09, 2009 2:17 pm

Your /index.html file contains
Code: Select all
<p>We also have free Adobe <a href="tutorials/photoshop/photoshop.html">

it needs to be
Code: Select all
<p>We also have free Adobe <a href="/photoshop.html">

The same for all other links.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby helpvid » Fri Oct 09, 2009 3:16 pm

Right that worked with the text in my opening statment, but still when I go through the Navigation Bar Links the folders remain in the URL.

I feel like giving up, Is this really worth all the hastle I am thinking. I really want my site seo friendly and to look neat. But I am begining to think this is taking way to much of my time, everything has been put on hold for 3 days. All I have been doing is this for days. I appreciate you taking the time my friend
helpvid
 
Posts: 15
Joined: Thu Oct 08, 2009 2:17 pm

Next

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 12 guests

cron