Welcome to WebmasterWorld Guest from 54.242.224.250

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Help with HTACCESS & REWRITE rules

htaccess, rewrite, rules, dynamic URLs

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

New User

joined:May 28, 2012
posts: 2
votes: 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
11:52 am on May 28, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 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.
4:48 pm on June 5, 2012 (gmt 0)

New User

joined:May 3, 2012
posts: 23
votes: 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
6:21 pm on June 5, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 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.
6:42 pm on June 5, 2012 (gmt 0)

New User

joined:May 28, 2012
posts: 2
votes: 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.
6:52 pm on June 5, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 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.
10:31 pm on June 5, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10563
votes: 15


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.
5:17 am on June 6, 2012 (gmt 0)

New User

joined:May 3, 2012
posts: 23
votes: 0


@g1smd

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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members