homepage Welcome to WebmasterWorld Guest from 54.204.77.26
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

    
TO use OR conditions between URL to redirect
sweetguyzzz




msg:3929401
 9:47 am on Jun 9, 2009 (gmt 0)

#Redirect sub pages of category having extension of .php to .htm
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+)/([^.]+).php[?]?[^\ ]*\ HTTP/
RewriteRule ^([^/]+)/([^.]+).php$ http://www.example.com/$1/$2.htm? [R=301,L]

#Giving all php pages htm extension
RewriteRule ^(.*)\.htm$ $1.php [L]

I am using above to redirect my all php pages in some category to .htm extension but the problem is that I have eleven (11) categories and want to redirect 10 categories sub pages to .htm but not a one mean if I have categories like

apple
banana
orange
mange
onion....

so I want to redirect all fruits except onion
Given example above is just a example not a real category

please reply fast
I will be thankful to all who will help me in making a right query

[edited by: jdMorgan at 6:18 pm (utc) on June 9, 2009]
[edit reason] example.com [/edit]

 

jdMorgan




msg:3929785
 6:19 pm on Jun 9, 2009 (gmt 0)

We need to know what a 'fruit' URL and an 'onion' URL look like in order to answer this question. We do not know the position of your 'categories' in your URLs.

Please provide at least two examples, using example.com as the domain name.

Jim

sweetguyzzz




msg:3930097
 4:08 am on Jun 10, 2009 (gmt 0)

Jim thanks for your reply

#Redirect sub pages of category having extension of .php to .htm
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /cateogry/pagename.php[?]?[^\ ]*\ HTTP/
RewriteRule ^category/pagename.php$ http://www.example.com/category/pagename.htm? [R=301,L]

#Giving all php pages htm extension
RewriteRule ^(.*)\.htm$ $1.php [L]

-------I am using my query like the above but

#Redirect sub pages of category having extension of .php to .htm
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /mango/pagename.php[?]?[^\ ]*\ HTTP/
RewriteRule ^mango/pagename.php$ http://www.example.com/mango/pagename.htm? [R=301,L]

#Giving all php pages htm extension
RewriteRule ^(.*)\.htm$ $1.php [L]

----The above category which is mango I want all of its pages to redirect .html version when anyone open its .php extension page

Now I want to do some thing like that in a single query that when anyone ask for the page present in onion category then it will not redirect it to .html version like if visitor ask for

www.example.com/allcategoies/pagename.php then redirect to
www.example.com/allcategoies/pagename.html

BUT
in all categories except ONION... like if ask for

www.example.com/onion/pagename.php then I do not want it to redirect to .html version
www.example.com/onion/pagename.php

I want to do all this in single query so is it possible?
Please reply me waiting for it
Thanks in Advance

jdMorgan




msg:3930401
 2:05 pm on Jun 10, 2009 (gmt 0)

So test the first URL-path part requested by the client, and skip the rule if it is "onion":

# Redirect sub pages of categories ([i]except onion[/i]) having extension of .php to .htm
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+)/([^.][b]+)\.p[/b]hp[?]?[^\ ]*\ HTTP/
[i]RewriteCond %1 !=onion[/i]
RewriteRule ^([^/]+)/([^.][b]+)\.p[/b]hp$ http://www.example.com/$1/$2.htm? [R=301,L]

Note that I corrected the missing escape characters on the literal periods in both regex patterns.

Jim

sweetguyzzz




msg:3930494
 4:00 pm on Jun 10, 2009 (gmt 0)

Ok I just run it and it works but what I want to do for the onion category ?

jdMorgan




msg:3930511
 4:17 pm on Jun 10, 2009 (gmt 0)

I don't know what you want to do with it... I'm afraid only you know what you want to do with it.

reviewing your posts above, it does not seem that you want to do anything with it. You said you wated to redirect all categories but onion, and that is what the modified rules does.

Jim

sweetguyzzz




msg:3930557
 5:04 pm on Jun 10, 2009 (gmt 0)

Ok

now I just place my real category name in place of onion but it does redirect the pages of that category. I just remove the sign "!" before the "=" sign which I thinks give the mean not equals to but after removing "!" sign it does not redirect any other category pages including my ONION category pages .... so now what is the best solution sir!

Thanks for great help
Now waiting for another reply

jdMorgan




msg:3930575
 5:24 pm on Jun 10, 2009 (gmt 0)

The best solution is not to try to "guess" or modify code that you do not completely understand. The "!" is required, and I would not have put it in the code if it were not required.

Check the spelling of the string that you substituted for "onion." It must be exactly correct, including uppercase/lowercase, and it must not start with, end with, or contain a slash.

The problem is not likely with the code. The problem is likely that your requirements have not been stated clearly here. That is, the code meets your requirements as I understand them from what you have written here, but what you have written here does not precisely describe your actual requirements. (This code is quite trivial, but describing and understanding exactly what you want the code to do is not trivial. This is a very common problem in the software world.)

Jim

sweetguyzzz




msg:3930581
 5:28 pm on Jun 10, 2009 (gmt 0)

Hey it just work its my own problem doing something wrong but now it just work and I am very delighted and thankful to the great personality JIM

Hey I have another problem in my web so can you please figure me out with that ? If you agree then I paste my problem else will be very thankful to you and never forget you man

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