homepage Welcome to WebmasterWorld Guest from 54.196.162.238
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Help with HTACCESS & REWRITE rules
htaccess, rewrite, rules, dynamic URLs
RogersAccount




msg:4458587
 11:45 am on May 28, 2012 (gmt 0)

I am having some 'fun' with HTACCESS and rewite rules...

I am trying to simply "divert" one specific page to another, so:
"/generate.php?article=48" = "/page_ducks.php"

Any help appreciated,
Roger

 

g1smd




msg:4458589
 11:52 am on May 28, 2012 (gmt 0)

This is a question that is asked approximately every two days, and so there are at least several thousand previous answers to peruse.

Use a RewriteRule inspecting the requested path and a preceding RewriteCond to look at the QUERY_STRING value. The target will require the full hostname and the [R=301,L] flags.

Post your code for discussion.

gagankkharbanda




msg:4461699
 4:48 pm on Jun 5, 2012 (gmt 0)

here is your answer...

RewriteCond %{QUERY_STRING} ^article=48$
RewriteRule ^generate\.php$ NEW URL? [R=301,L]

@ g1smd...This question is not asked every two days but i have seen this question everyday or even twice a day but unfortunately answer is hard to find (I know this as i too tried a lot and spend almost a week in answer)...
You have to understand that the pple seeking help are not professionals like you and it would be very difficult for them to find out the answer, if you / me or anyone knows the answer than better to increase the number of solution rather than telling that how much time is question has been asked

g1smd




msg:4461730
 6:21 pm on Jun 5, 2012 (gmt 0)

You have to understand I have paid work to do, there are only four people who regularly answer questions in this forum, and the number of questions posted exceeds the resources available to answer every one.

In many cases I find myself simply cutting and pasting answers from a discusion from last week or last month, over and over again. The forum charter asks that people post their code for discussion. This is a "teach a man to fish" exercise. It explicitly mentions that WebmasterWorld is not a free "write your code for you service".

There are 80 000 threads and almost every conceivable problem has been covered dozens or hundreds of times. Sure it is difficult to wade through lots of information, but read as much as you can, try code out on a test server, test thoroughly and one day the light bulb goes on and you realise you actually understand it all.

It took me three years to get there.

RogersAccount




msg:4461735
 6:42 pm on Jun 5, 2012 (gmt 0)

Thank you for the help and direction.

The code used was:

RewriteEngine on
RewriteCond %{REQUEST_URI} /generate.php$
RewriteCond %{QUERY_STRING} ^article=48
RewriteRule ^generate.php$ /page_ducks.php [R=302,L]

RewriteCond %{REQUEST_URI} /generate.php$
RewriteCond %{QUERY_STRING} ^article=49
RewriteRule ^generate.php$ /page_swans.php [R=302,L]


Hope this helps someone else.

g1smd




msg:4461739
 6:52 pm on Jun 5, 2012 (gmt 0)

Escape literal periods in patterns.

The rule will work only if article is the first parameter.

The redirect target should include the full protocol and domain.

The rule will redirect when the paramter value is 480 or 4800 and anything else that begins "48".

The RewriteCond looking at REQUEST_URI is redundant as it duplicates the pattern used in the RewriteRule.

phranque




msg:4461823
 10:31 pm on Jun 5, 2012 (gmt 0)

welcome to WebmasterWorld, RogersAccount!

it is very likely that you would prefer to use a 301 instead of a 302.
301 implies a permanent redirect and 302 implies a temporary redirect.

for example if a search engine sees that response it will index the /page_ducks.php content for the /generate.php?article=48 url.

gagankkharbanda




msg:4461906
 5:17 am on Jun 6, 2012 (gmt 0)

@g1smd

Then we should request moderator to start some topics which will stick to top with reference for such common redirects..

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved