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
 
Thread Tools Display Modes
Share |
  #1  
Old 04-22-2011, 11:06 AM
kads kads is offline
Junior Member
 
Join Date: 01-17-11
Posts: 20
iTrader: 0 / 0%
is my htaccess code correct and safe?

The code is:
Code:
RewriteEngine On RewriteCond %{HTTP_HOST} ^domain.com [NC] RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]

The reason I ask is because I see so many variations of this with different notations like the characters !, /, different arrangements of letters etc, is that it isn't clear which one is correct or safe.

Is the above method perfectly safe, and as applicable as any other method of doing the above?


Thanks in advamce

Last edited by HTMLBasicTutor; 04-22-2011 at 11:32 AM.
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 04-22-2011, 12:19 PM
kos's Avatar
kos kos is offline
Coding Tiger
 
Join Date: 04-13-07
Location: .ro
Posts: 4,029
iTrader: 3 / 100%
I'd go for a cleaner route:
Code:
RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
what this will do is redirect ALL non-www requests to www (as yours does too).
you can also use it on multiple websites without having to edit it every time you deploy it on a new domain name (this is the clean part).
 
Reply With Quote
  #3  
Old 04-22-2011, 02:13 PM
kads kads is offline
Junior Member
 
Join Date: 01-17-11
Posts: 20
iTrader: 0 / 0%
thanks for that

but is the method I mentioned safe? As in there will be NO adverse effects with that specific notation? Since many people put additional characters like !, / etc
 
Reply With Quote
  #4  
Old 04-22-2011, 02:42 PM
kos's Avatar
kos kos is offline
Coding Tiger
 
Join Date: 04-13-07
Location: .ro
Posts: 4,029
iTrader: 3 / 100%
yes, it's safe alright

those characters have special meaning when part of a regular expression, and because htaccess allows the use of regular expressions inside it everyone uses them to best fit their requirements, so you'll see a lot of those characters inside an htaccess file, but that doesn't mean you have to have them too if you don't need them
 
Reply With Quote
  #5  
Old 05-03-2011, 04:31 AM
nullifygirls nullifygirls is offline
Contributing Member
 
Join Date: 03-15-11
Posts: 77
iTrader: 0 / 0%
whats happen.
It is very simple.
 
Reply With Quote
  #6  
Old 05-03-2011, 08:13 AM
nemrod's Avatar
nemrod nemrod is offline
v7n Mentor
 
Join Date: 12-21-10
Location: Sweden
Posts: 463
iTrader: 0 / 0%
Quote:
Originally Posted by kos View Post
I'd go for a cleaner route:
Code:
RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
what this will do is redirect ALL non-www requests to www (as yours does too).
you can also use it on multiple websites without having to edit it every time you deploy it on a new domain name (this is the clean part).
It is important to note that with this method it will redirect all requests with any subdomain other than www to with www. In other words, if you use any other subdomains (that resolve to a server with that .htaccess) they will be redirected. If this is the sought-after behavior then it's not a problem, but otherwise it might cause unexpected problems in the future when you thought you'd start using subdomains and all of a sudden it doesn't work and you don't know why. Otherwise it's portable and nice, just wanted to clarify further.
 
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need 'deny all referrers except x' .htaccess code vectro Coding Forum 6 10-27-2010 03:18 PM
is it correct dhruva SEO Forum 15 03-02-2010 10:32 PM
Conflict, What is the right htaccess rule, default homepage file with htaccess? basketmen Coding Forum 2 01-20-2009 08:50 AM
Safe redirect...I mean SAFE redirect...I really mean SAFE rrl Google Forum 1 08-16-2004 03:40 PM


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


All times are GMT -7. The time now is 10:01 PM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC