?
Solved

.HTACCESS rewrite help needed

Posted on 2014-01-31
9
Medium Priority
?
248 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
8 Comments
 
LVL 35

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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 35

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
 

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 35

Assisted Solution

by:gr8gonzo
gr8gonzo earned 2000 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 35

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 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