Forum Moderators: phranque

Message Too Old, No Replies

Remove folder from URL, Using Rewrite

         

helpvidnet

11:51 am on Jan 25, 2010 (gmt 0)

10+ Year Member



Hi, I am trying to eliminate a folder from appearing in my URL. I done this months ago but no longer have the code.

Example
I am trying to eliminate the folder named "2009" from appearing in the URL. At the moment the path reads
http://www.example.com/news/2009/1048-boxing-2010.html

I am looking for it to read.
http://www.example.com/news/1048-boxing-2010.html

As I said I had this working weeks ago but missplaced the code, I have been trying the following Rewrite rule

#Check inf the file exists in /news/2009.
RewriteCond%{DOCUMENT_ROOT}/news/2009/$09 -f
RewriteRule ^[^/]+\.html$ /news/2009/$0 [QSA.L]

[edited by: jdMorgan at 2:53 pm (utc) on Jan. 25, 2010]
[edit reason] example.com [/edit]

jdMorgan

3:03 pm on Jan 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Back-references do not start with "0". Back-references created by RewriteRule range from $1 to $9, and back-references created by RewriteConds range from %1 to %9. $0 is not mentioned in the mod_rewrite documentation, and will be undefined on some servers.

# If the requested localized URL-path resolves to an existing file when "/news/2009"
# is prepended to it, rewrite the request to the /news/2009 subdirectory
RewriteCond %{DOCUMENT_ROOT}/news/2009/$1 -f
RewriteRule ^([^/]+\.html)$ /news/2009/$1 [QSA.L]

Because of the construction of your original patterns and substitution, I assume that this code goes into "/news/.htaccess". If not, then further changes are needed to correctly localize the requested URL-path.

Jim

helpvidnet

5:26 pm on Jan 25, 2010 (gmt 0)

10+ Year Member



So will I need to change .htaccess to /news/.htaccess

I only want to eliminate the 2009 folder, the news folder must stay as that is where Google News is directed.

jdMorgan

1:43 am on Jan 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> So will I need to change .htaccess to /news/.htaccess

No, not necessarily. But your code was written to work in /news/.htaccess

It all depends on what you want...

Jim