Solved

mod rewrite issue

Posted on 2013-06-02
8
274 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

831 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