Solved

.htaccess redirect if file exists

Posted on 2014-10-10
1
157 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
[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
1 Comment
 
LVL 51

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 40374824
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

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.

Question has a verified solution.

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

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

688 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