Solved

.HTACCESS rewrite help needed

Posted on 2014-01-31
9
237 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MDB2 Error: not found 4 188
htaccess file errors for 301 Redirect 4 80
Apache error.log 19 43
Recommendations for Web-Based Multi-User File Manager / FTP software? 4 91
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). #…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

770 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