Solved

.htaccess redirect if file exists

Posted on 2014-10-10
1
155 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 50

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RewrteRule using htacess 10 81
Problem to go to page 12 110
Need To Change Centos 6 Timestamp Form In Log File 24 117
Web site: http forwards to https causing 301 errors - SEO issue? 26 55
As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
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 …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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