Solved

.htaccess redirect if file exists

Posted on 2014-10-10
1
147 Views
Last Modified: 2014-10-14
Hi,

I'm hoping this is an easy one but I can't figure it out.

Here's my current .htaccess file

RewriteEngine on

# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

# Handle redirection to routes
RewriteRule     ^public/(.*) app/routes/public/www/$1 [L]
RewriteRule     ^admin/(.*) app/routes/admin/www/$1 [L]

# Handle framework requests
RewriteRule ^(.*)$ framework/index.php$1  [L]

Open in new window


On these lines,
RewriteRule     ^public/(.*) app/routes/public/www/$1 [L]
RewriteRule     ^admin/(.*) app/routes/admin/www/$1 [L]
How do I set these to only redirect if the requested file actually exists at the new location? Otherwise continue to process the rest of the .htaccess file?

Bascially, I don't want to redirect /admin/ to app/roues/admin/www/ but /admin/css/style.css should redirect to app/routes/admin/www/css/style.css ok as it's an actual file.
0
Comment
Question by:SheppardDigital
1 Comment
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
Comment Utility
Try this:
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule     ^public/(.*) app/routes/public/www/$1 [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule     ^admin/(.*) app/routes/admin/www/$1 [L]

Open in new window

Change the '-f' to '-s' if you want to also ensure the file has a size to it (i.e., content).
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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). #…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

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

15 Experts available now in Live!

Get 1:1 Help Now