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
Solved

.htaccess redirect if file exists

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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

790 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