.htaccess redirect question (dynamic urls)

This is a discussion on .htaccess redirect question (dynamic urls) within the Apache Web Server forums, part of the Web Server and Related Forums category; Hi all, I have the following .htaccess file: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-18-2006
Byru
 
Posts: n/a
Default .htaccess redirect question (dynamic urls)

Hi all,

I have the following .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,NS]

This works great. I recently redesigned the website and i am using other
link structure than before. I would like to make the old links still
available. Here it is how they looked like:

some links were with /
http://www.domain.com/index.php?s=some/thing or
http://www.domain.com/?s=some/thing

and some without /
http://www.domain.com/index.php?s=something or
http://www.domain.com/?s=something

What should i add to my htaccess to redirect those old links which are still
used in the internet to the new locations following this pattern:

http://www.domain.com/index.php?s=some/thing should go to
http://www.domain.com/something/ instead.

and

http://www.domain.com/index.php?s=something should go to
http://www.domain.com/something/ instead as well.

I tried to add the following sample line to the end of htaccess file but
with no luck
Redirect PERMANENT /index.php?s=some/thing http://www.domain.com/something/

By dynamic urls i mean that the some/thing and something variables could be
anything.

TIA for help :)

Byru

  #2 (permalink)  
Old 12-22-2006
shimmyshack
 
Posts: n/a
Default Re: .htaccess redirect question (dynamic urls)

I am assuming you are using a web application like wordpress or
something else, and that the htaccess rules were put in place by it
when you changed your link structure.
Adding redirects at the end of the .htaccess file wont work because of
the [L] switch after the rewriterule which means Last.
If you think about it you cant really have both the old and new links.
The old send arguments as a query string into the web application which
processes the GET array and then takes those values. The new rewrite
rule simply sends the entire requested string to the application which
then processes that long URI and splits it up into various parts.
So if you want to retain the rewrite rule which means you can use
pretty URLs - remember it will grab the whole requested URI and sends
it to the application, you will have to write some code in the
application that recognises that a string of the old form has been sent
and simply splits it up into the bits required. To be honest thats
something I would expect from said application anyway, but it should be
too hard to do.
The old wordpress used about a page of rewrite rules to achieve pattern
matching for your blog, so good luck with that if you want to have some
huge .htaccess file! Easier to add to the application logic methinks,
you'll get help from your application's public forum, or a php group.


Byru wrote:
> Hi all,
>
> I have the following .htaccess file:
> RewriteEngine On
> RewriteBase /
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteRule . /index.php [L,NS]
>
> This works great. I recently redesigned the website and i am using other
> link structure than before. I would like to make the old links still
> available. Here it is how they looked like:
>
> some links were with /
> http://www.domain.com/index.php?s=some/thing or
> http://www.domain.com/?s=some/thing
>
> and some without /
> http://www.domain.com/index.php?s=something or
> http://www.domain.com/?s=something
>
> What should i add to my htaccess to redirect those old links which are still
> used in the internet to the new locations following this pattern:
>
> http://www.domain.com/index.php?s=some/thing should go to
> http://www.domain.com/something/ instead.
>
> and
>
> http://www.domain.com/index.php?s=something should go to
> http://www.domain.com/something/ instead as well.
>
> I tried to add the following sample line to the end of htaccess file but
> with no luck
> Redirect PERMANENT /index.php?s=some/thing http://www.domain.com/something/
>
> By dynamic urls i mean that the some/thing and something variables could be
> anything.
>
> TIA for help :)
>
> Byru


 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:20 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0