Solved

mod rewrite issue

Posted on 2013-06-02
8
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
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…

740 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