PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Aug 18, 2018 4:14 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: [RegEx] - ReWrite rule
PostPosted: Thu Jun 28, 2012 6:11 pm 
Offline
Forum Newbie

Joined: Thu Jun 28, 2012 6:05 pm
Posts: 8
Hello folks!

This is my first post here and I need some help regarding RegEx.

I need to make a Rewrite rule. Basically I have 3 situations:

1) www.mydomain.com
2) www.mydomain.com/?utm_source=source&utm ... aign=blogs (Google URL Builder)
3) www.mydomain.com/blog or /chat, etc

With situations 1 and 2 I need the rewrite rule to be active. But with situation 3, I don't want a redirect.

So, I was wondering if this is correct:

1) ^(http[s]?://)?(www\.)?(mydomain\.com[/]?)$
2) ^(http[s]?://)?(www\.)?(mydomain\.com[/]?)$([?]utm_source[=])
3) Nothing

Is that right? Is this secure? Okay?

Or there is any other way to put just 1 single rule for all 3 situations?

Thanks a lot in advance!!!!!


Top
 Profile  
 
PostPosted: Thu Jun 28, 2012 6:12 pm 
Offline
Forum Newbie

Joined: Thu Jun 28, 2012 6:05 pm
Posts: 8
Oh... I almos forget!

In situation 2, I need that the parameters (utm_source, etc) to go to the next page, so I can handle them

So, I'm almost sure that I made it wrong, I miss something, right?

Thanks again!


Top
 Profile  
 
PostPosted: Fri Jun 29, 2012 12:40 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
And where are those redirects to?


Top
 Profile  
 
PostPosted: Fri Jun 29, 2012 7:12 am 
Offline
Forum Newbie

Joined: Thu Jun 28, 2012 6:05 pm
Posts: 8
Will redirect to

http://www.mydomain.com/pub/index.htm


Top
 Profile  
 
PostPosted: Fri Jun 29, 2012 9:58 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
Does 1 require "the query string is empty"? If not then you can forget about 2 because 1 covers it. Then all you're doing is redirecting away from the homepage.
Otherwise you're still redirecting from the same page, you just need two RewriteRules each with a RewriteCond for the query string.

Oh, and RewriteRules do not process the query string. Only the path and filename.


Top
 Profile  
 
PostPosted: Mon Jul 02, 2012 7:16 am 
Offline
Forum Newbie

Joined: Thu Jun 28, 2012 6:05 pm
Posts: 8
What I want to do is that when the user typer mydomain.com OR mydomain.com/utm_source=source he goes to mydomain.com/pub/index.htm

But, if typer mydomain.com/chat or mydomain.com/blog, he goes to the specific page

And, when the page is mydomain.com/utm_source=source I need to get the info after utm_source

Thanks a lot!


Top
 Profile  
 
PostPosted: Mon Jul 02, 2012 11:17 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
You can use a RewriteCond to look at the query string, then pair that with a RewriteRule (that only looks at the path/file) to redirect. Like
Code:
# contains utm_source
RewriteCond %{QUERY_STRING} (^|&)utm_source=([^&]+) [OR]
# it's empty
RewriteCond %{QUERY_STRING} ^$
# QSA=pass all the query string arguments in the new URL
RewriteRule ^$ /pub/index.htm [L,QSA]

You might want an [R] in there, I'm not sure.


Top
 Profile  
 
PostPosted: Tue Jul 03, 2012 3:14 pm 
Offline
Forum Newbie

Joined: Thu Jun 28, 2012 6:05 pm
Posts: 8
Thanks a lot for your answer requinix, but as I'm a newbie, a don't know if I want a [R] there, because I don't know what it does.

Is it possible to you to make the cond and the rewrite rules?

I ask this because I really do not have a clue on this.

No idea how to get where I want ;(

Thanks a lot in advance!


Top
 Profile  
 
PostPosted: Tue Jul 03, 2012 9:08 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
gscrmn wrote:
as I'm a newbie, a don't know if I want a [R] there, because I don't know what it does.

Normally URL rewriting works behind-the-scenes: the browser doesn't know about the redirect. Using an [R] (for redirect) means the browser is told where to go instead. That also means the user sees the URL change to the new location. And also means it's a lot less likely that people will continue going/clicking links to the old URL.

gscrmn wrote:
Is it possible to you to make the cond and the rewrite rules?

...Again?


Top
 Profile  
 
PostPosted: Wed Jul 04, 2012 1:09 pm 
Offline
Forum Newbie

Joined: Thu Jun 28, 2012 6:05 pm
Posts: 8
Thanks a lot again requinix, I'm almost there.

So if I add this instructions:

RewriteCond %{QUERY_STRING} (^|&)utm_source=([^&]+) [OR]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^$ /pub/index.htm [L,QSA]

When a user types:
1) http://www.mydomain.com - He will be redirect to http://www.mydomain.com/pub/index.htm
2 http://www.mydomain.com/?utm_source=... - He will be redirect to http://www.mydomain.com/pub/index.htm?utm_source=...
3) http://www.mydomain.com/chat or /blog or /anythingelse - No redirect happens

Is that correct?

And 2 other doubts:

1) Will the visitor "visit" my index.php at the root directory or the redirect happens BEFORE this?
2) I want the page to ALWAYS redirect, this will be a permanent redirect. So, in your opinion, is better to put a R?

Thanks again!!!


Top
 Profile  
 
PostPosted: Wed Jul 04, 2012 5:35 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
gscrmn wrote:
So if I add this instructions:

RewriteCond %{QUERY_STRING} (^|&)utm_source=([^&]+) [OR]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^$ /pub/index.htm [L,QSA]

When a user types:
1) http://www.mydomain.com - He will be redirect to http://www.mydomain.com/pub/index.htm
2 http://www.mydomain.com/?utm_source=... - He will be redirect to http://www.mydomain.com/pub/index.htm?utm_source=...
3) http://www.mydomain.com/chat or /blog or /anythingelse - No redirect happens

Is that correct?

1. Try it and see.
2. Given my explanation of what [R] does, do you think you want it?

gscrmn wrote:
1) Will the visitor "visit" my index.php at the root directory or the redirect happens BEFORE this?

Before.

gscrmn wrote:
2) I want the page to ALWAYS redirect, this will be a permanent redirect. So, in your opinion, is better to put a R?

I never said anything about (vanilla) [R] being a permanent redirect. If you want that then the syntax would be [R=301].


Top
 Profile  
 
PostPosted: Thu Jul 05, 2012 1:01 pm 
Offline
Forum Newbie

Joined: Thu Jun 28, 2012 6:05 pm
Posts: 8
1. Try and see is the worst option, because if it fails, my entire website will not be functional, so it is definetly not a good idea. This is the main reason why I'm here: to ask for help. To try and see, I could do a basic Google search. I need to be sure that it will work.
2. I don't got your explanation about [R], sorry. Lot less likely that people will continue going/clicking links to the old URL is worthless, because I need people keep going on that "link" because it is my MAIN DOMAIN. And does not make difference if the user sees the URL changing.

I know you never said anything about (vanilla) [R] being a permanent redirect. But I want it to be, because it is not temporary, it is forever. Every time that someone type my web address, it has to be redirect.

But thanks for your cooperation. You where the only one that always give me answers. At all!


Top
 Profile  
 
PostPosted: Thu Jul 05, 2012 9:17 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
gscrmn wrote:
1. Try and see is the worst option, because if it fails, my entire website will not be functional, so it is definetly not a good idea.

Then thank God that you write perfect, 100% bug-free code, because if there ever was a flaw then all your users could see it!
gscrmn wrote:
This is the main reason why I'm here: to ask for help. To try and see, I could do a basic Google search. I need to be sure that it will work.

Help is what I've been giving you, but in return I expect you to try to help yourself. You don't quite understand [R] yet? Okay: where else have you looked for information? The mod_apache documentation? How about a basic Google search?

And one more thing: if you think the information you get on the Internet will always work then you don't understand what the Internet is. Not only are you trusting a bunch of people you don't know, you don't even have some way of testing what they've said. What if your setup is unusual? If you don't have mod_rewrite installed then even a perfect example of how to use RewriteRule would crash your site.

gscrmn wrote:
2. I don't got your explanation about [R], sorry. Lot less likely that people will continue going/clicking links to the old URL is worthless, because I need people keep going on that "link" because it is my MAIN DOMAIN. And does not make difference if the user sees the URL changing.

Okay. So the generic information I gave doesn't quite apply entirely to your specific situation.

gscrmn wrote:
I know you never said anything about (vanilla) [R] being a permanent redirect. But I want it to be, because it is not temporary, it is forever. Every time that someone type my web address, it has to be redirect.

Great. Then it's good that I pointed it out before you came back and told me it wasn't working.


Top
 Profile  
 
PostPosted: Fri Jul 06, 2012 2:20 pm 
Offline
Forum Newbie

Joined: Thu Jun 28, 2012 6:05 pm
Posts: 8
What I have to say is I'm sorry!

You are ABSOLUTELY right, 100%!

I'm so sorry about what I said, you have the reason when you say about test and help.

You just tried to help, but I'm a little ancious to have it working, because I'm trying to make it functional about 10 days and did not got it!!!!!

But thank you and shame on me!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group