Forum Moderators: phranque

Message Too Old, No Replies

How to remove part of my url with htaccess?

htaccess, mod_rewrite

         

freaksauce

11:40 pm on Feb 27, 2011 (gmt 0)

10+ Year Member



My typical url for my site is something like this:

[guitarnoize.com...]

I want to completely remove /blog/comments/ as this is totally unnecessary for my blog. I'm a total htaccess n00b and currently have this:


RewriteCond %{HTTP_HOST} !^www\.guitarnoize\.com$ [NC]
RewriteRule ^(.*)$ http://www.guitarnoize.com/$1 [R=301,L]

RewriteCond $1 !^(images|js|themes|2007|labels|techniques|mp3|gn_system|css|swf|) [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]


I removed some of the other directories and pages that are accepted by the RewriteCond too as it was quite long, if there is a better way to do this too like the opposite way around that would be great.

g1smd

11:48 pm on Feb 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The first step in removing the /blog/comments/ part of the URL is to change the links on your pages to specify the correct URLs. It is links that "define" URLs.

Next you'll need a redirect such that should someone request an old URL (from browser bookmarks or history, or a stale searchengine results page), your server will send a redirect telling the browser to make a new request for a the new URL. This is a URL to URL suggestion.

Next, you'll need a rewrite that detects a request for the new URL and rewrites it to fetch the content from the real location inside the server where that content resides. This is a URL to filepath translation.

You need to be totally clear as to the difference between a rewrite and a redirect, and be sure that you know the difference between a URL "used out on the web" and a filepath "used inside the server". Without that understanding, coding is impossible.

This is a question that comes up almost every day, and there are literally thousands of posts with example code.

Other people are asking similar questions. Indeed the answer I typed 10 minutes ago in another thread is very much along the same lines as is the answer I typed about an hour prior to that in another thread here.

freaksauce

12:06 am on Feb 28, 2011 (gmt 0)

10+ Year Member



Thanks, ok so its a lot more involved than I first thought. I did a quick search but figured my current htaccess might be wrong and cause issues.