Solved

mod rewrite issue

Posted on 2013-06-02
8
271 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now