Webmaster Forum


Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Share |
  #1 (permalink)  
Old 05-14-2012, 04:29 PM
Member
Latest Blog:
None

 
Join Date: 05-19-11
Location: Poland
Posts: 35
iTrader: 1 / 100%
mod_rewrite - simple rule

Hi guys,

I'm newbie to using apache mod_rewrite. I've tried to create the rule that replace the domain only for URL that are longer than www.mydomain.com or not ending with .php. If that the case I would like to replace the domain. For instance:

1) http://www.mydomain1.com/Object/Subobject should be changed to
www.mydomain2.com/Object/Subobject

2) http://mydomain1/com/Objects also shlould be modified , into:
http://mydomain2/com/Objects

but urls like:
http://www.mydomain1.com , http://mydomain1.com/ , http://www.mydomain1.com/something.php, http://mydomain1.com/something.php

should stay with no change. What would be the entry to .htaccess for such rules ?
 
Reply With Quote
  #2 (permalink)  
Old 05-15-2012, 07:12 PM
Member
Latest Blog:
None

 
Join Date: 05-19-11
Location: Poland
Posts: 35
iTrader: 1 / 100%
I studied quite few tutorials and now I think I know basics. I prepared the rules for that

version1:

1) RewriteEngine On
2) RewriteCond %{REQUEST_URI} !php$
3) RewriteCond %{REQUEST_URI} !^$
4) RewriteRule .? http://www.mydomain2.com%{REQUEST_URI} [R]


version2:

1) RewriteEngine On
2) RewriteCond %{REQUEST_URI} !php$
3) RewriteCond %{HTTP_REFERER} ^mydomain1\.com/?$
4) RewriteRule .? http://www.mydomain2.com%{REQUEST_URI} [R]

2) pass through if URL doesn't end with php
3) pass through if there is nothing after domain name


Any idea why none of above is working ?
RewriteRule works fine, but RewriteCond not.
 
Reply With Quote
  #3 (permalink)  
Old 05-17-2012, 02:01 PM
Member
Latest Blog:
None

 
Join Date: 05-19-11
Location: Poland
Posts: 35
iTrader: 1 / 100%
I figured out where the problem was. At RewriteRule the RegExp applies only to the part of URL after host name which was very hard to find. The correct entry looks as follows:


RewriteEngine On
RewriteCond %{REQUEST_URI} !php$
RewriteRule (.+) http://www.mydomain2.com%{REQUEST_URI} [R]

The key point was (.+) which means 1 or more chars after the domain what guaranties that the RewriteRule will take an effect if there will be anything after www.domain1.com/
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple mod_rewrite question surfinglight Coding Forum 4 07-08-2005 05:13 AM
Mod_Rewrite GeXus Coding Forum 8 07-10-2004 01:43 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 11:30 AM.
Powered by vBulletin
Copyright © 2000-2013 Jelsoft Enterprises Limited.
Copyright © 2003 - 2013 Escalate Media LP




Search Engine Optimization by vBSEO 3.6.0 RC 2 ©2011, Crawlability, Inc.