?
Solved

.HTACCESS rewrite help needed

Posted on 2014-01-31
9
Medium Priority
?
244 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
[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
9 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
Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

 
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

766 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