Solved

.HTACCESS rewrite help needed

Posted on 2014-01-31
9
233 Views
Last Modified: 2014-02-08
This is my .htaccess:

# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
</IfModule>
# END YOURLS



I need to make sure that the www is stripped from what the user types in the url.  If the user includes www ie: http://www.domain.com/lent my php script does not work.  It only works if you use http://domain.com/lent

As you can see, the info after the / must be passed to yourls-loader.php

Thanks.
0
Comment
Question by:jasgot
  • 4
  • 4
9 Comments
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 39824169
Check out this article:
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Apache/A_10732-The-Basics-of-htaccess-Files-and-URL-Redirection.html

The first example is about redirecting non-www traffic to www. You'd just need to invert the condition and action.
0
 

Author Comment

by:jasgot
ID: 39837433
I googled my problem and found an exact answer. Thank you.
0
 

Author Comment

by:jasgot
ID: 39841290
I've requested that this question be closed as follows:

Accepted answer: 0 points for jasgot's comment #a39837433

for the following reason:

Found the answer on my own.
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 39841291
Can you elaborate on why my suggestion didnt work for you? It was pretty much exactly what you were talking about..m
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:jasgot
ID: 39841689
I was unable to convert the info in that article to meet my needs. I found an exact drop in snippet elsewhere. For 500 points, I expected an answer not a research project.
0
 
LVL 34

Assisted Solution

by:gr8gonzo
gr8gonzo earned 500 total points
ID: 39842077
That's unfortunate. If you can't convert the first code snippet in that article (non-www to www) into what you need by essentially removing a ! and tweaking the redirect, then an exact snippet isn't going to help you in the long run.

Articles that teach you this stuff are considered valid answers (not "research projects") by most people, since they are teaching you how to fish, not just feeding you for a day.

FWIW, the code snippet in that article to redirect non-www traffic to www is:

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

The first step would be to invert the condition:
RewriteCond %{HTTP_HOST} !^www\.
to
RewriteCond %{HTTP_HOST} ^www\.

Then the second step would have just been to put in the non-www host, like this::
RewriteRule ^(.*)$ http://yourhost.com/$1 [R=301,L]

Again, the article would have explained how all that works.
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 39842091
In any event, if you're going to close out the question by saying that you have a separate answer that is somehow vastly different than the above, please help future people who come across this question and share your answer and then accept it as the answer.
0
 

Accepted Solution

by:
jasgot earned 0 total points
ID: 39842456
# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.DOMAIN.org$ [NC]
RewriteRule ^(.*)$ http://DOMAIN.org/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
</IfModule>
# END YOURLS

The article I found made it clear that these two lines had to be above the ReWriteCond lines that were already there.

RewriteCond %{HTTP_HOST} ^www.DOMAIN.org$ [NC]
RewriteRule ^(.*)$ http://DOMAIN.org/$1 [R=301,L]


I tried many variants using the article you provided as a guide and could not make it work until I found these instructions using google.

I'm sorry you were unable to provide an answer that worked for me. It was kind of you to provide the link to an article about ReWrite, though.

In the future, please remember that sometimes people come to EE for an answer because there is not enough time to figure it out on their own.  Since EE allows direct answers, you shouldn't be upset with people who are looking for direct answers.

Perhaps a better approach in the future might be "Here's an article about your topic, and here is a snippet that should work for you".

Cheers.
0

Featured Post

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!

Join & Write a Comment

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

11 Experts available now in Live!

Get 1:1 Help Now