Solved

mod rewrite issue

Posted on 2013-06-02
8
275 Views
Last Modified: 2013-06-02
Hey guys, got a bit of a basic issue that I cant quite work out. Is pretty simple but I'm messing something up.

running ubuntu using .htaccess to perorm a rewrite on my webserver.

basicaly, I have 2 urls
mishmash.com
mishmash.com.au

I want them to both to go mishmash.com/blog/
The current rule I have works (below) however, I have just tried going to www.mishmash.com and the rewrite rule does not work. It goes to the root directory on my server (which is not the /blog/).

I've tried to add something to my rule, but it spits out something like this
mishmash.com/blog/blog/blog/blog/blog/blog and so on and so forth.

Any assitance would be great.
Cheers



Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mishmash.com.au$
RewriteRule ^$ http://mishmash.com/blog [L,R=301]

RewriteCond %{HTTP_HOST} ^mishmash.com$
RewriteRule ^$ http://mishmash.com/blog [L,R=301]
0
Comment
Question by:samabdelhamid
  • 4
  • 4
8 Comments
 
LVL 1

Expert Comment

by:ForFracksSake
ID: 39214384
Hey there,

I'm assuming you are currently using a version cPanel. There are several ways of doing this if this is the case:

1) Domain redirect in your Domain section of the cPanel. Very simple

2) In your public_html folder (also called the “root html” folder), you need to create a file called .htaccess. From this file we are going to use a few lines to redirect those requests in a search engine friendly way.

Add the following lines to that file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?YourDomain.com$
RewriteRule ^(/)?$ blog [L]

The only change you need to make is to change “YourDomain.com” to your domain. This will then redirect everything from the domain to the folder /blog at that domain. If you want to change that folder just edit the “blog” part
0
 

Author Comment

by:samabdelhamid
ID: 39214397
Thanks for the reply!

I ended up doing this (with.htaccess file)


RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mishmash.com$
RewriteRule ^(/)?$ blog [L]

RewriteCond %{HTTP_HOST} ^(www.)?mishmash.com.au$
RewriteRule ^(/)?$ blog [L]

which seems to be working. I didnt know how else to make one rule for both .com and .com.au domains....im sure its easy with regex, but I struggle with regex, so 2 rules seems to work..
0
 
LVL 1

Accepted Solution

by:
ForFracksSake earned 500 total points
ID: 39214402
Or.. this may be your best bet

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) http://www.example.com/store [R=301,L]



Remember, not everyone types the http:// , and www. is technically a subdomain. So you have to have that wildcard element in there as above shows. Let me know if this works bud.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 1

Expert Comment

by:ForFracksSake
ID: 39214408
One more thing. This article you may find handy as well. I pulled it from the Hostgator.com support portal (they have the best articles and KB's), and I find this useful and I work for another Hosting Company now.. that tells you something.

http://support.hostgator.com/articles/specialized-help/technical/apache-htaccess/apache-mod_rewrite-and-examples
0
 

Author Comment

by:samabdelhamid
ID: 39214419
That one works perfect!
Brilliant thank you!

I know there was a way to do it in 2 lines, I just couldn't figure it out.

I was originally happy with the first rule I had, but then someone told me that www. doesn't work (they were typing www in, I never do so I never guessed to test it..)

So if i understand correctly, your condition, takes Anything that's typed in, and replaces it with the rewrite rule. ?

Cheers
0
 

Author Closing Comment

by:samabdelhamid
ID: 39214422
Excellent answer. Excellent help.
0
 
LVL 1

Expert Comment

by:ForFracksSake
ID: 39214457
Basically, there's different ways for different situations. I was also thinking about the two line rule, but sometimes a particular way will work and others won't. .htaccess is a crazy thing sometimes. Good luck buddy!
0
 

Author Comment

by:samabdelhamid
ID: 39214550
Cheers! really appreciate the help :)
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Redirect URL's containing question marks 5 74
How to redirect https://www to non-www? 6 76
instanceof  operator in java 26 95
Redirect 301 from one address  to another 5 25
In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question