Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Re-write help

Posted on 2009-06-27
7
Medium Priority
?
218 Views
Last Modified: 2012-05-07
Hi,

I have the attached .htaccess file, which works great so far, but now I want to be able to specify folders which should not be included in the rewrite, i.e. images, css, and javascript etc

At the minute calls for images and javascript files are not working due to the rewrite
rewriteEngine on 
# This will handle any file that ends in php (like index.php)
RewriteCond %{HTTP_HOST} !^www\.digitalassetbag.com
RewriteCond %{REQUEST_FILENAME} php$
RewriteCond %{QUERY_STRING} !subdomain=
RewriteCond %{HTTP_HOST} ([^.]+)\.digitalassetbag.com
RewriteRule ^/?(.+)/?$ /$1?subdomain=%1 [QSA]
 
# This will handle URLs like /products
RewriteCond %{HTTP_HOST} !^www\.digitalassetbag.com
RewriteCond %{REQUEST_FILENAME} !php$
RewriteCond %{QUERY_STRING} !subdomain=
RewriteCond %{HTTP_HOST} ([^.]+)\.digitalassetbag.com
RewriteRule ^/?(.+)/?$ /$1.php?subdomain=%1 [QSA]

Open in new window

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
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:thinkingman2
ID: 24728995
Instead of specifically excluding certain folders, what I do is this: I just exclude anything that is already a valid filename from the Rewrite; the attached added lines should go right below the RewriteEngine On line in your .htaccess file. The first line excludes valid, existing directory names from the RewriteRule(s). The next line excludes valid filenames from the Rule.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

Open in new window

0
 

Author Comment

by:SheppardDigital
ID: 24804297
Hi,

Sorry for the delay, I've just got back from holiday.

That solution didn't work, it broke the rest of my re-write rules.
0
 

Author Comment

by:SheppardDigital
ID: 24894655
Can anyone help with this problem, all I want to do is exclude certain folders from the re-write, i.e. images and css etc
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 27

Accepted Solution

by:
caterham_www earned 2000 total points
ID: 24894885
You can simplify your rules a little bit. If you'd like to exclude a specific folder, use e.g.

RewriteCond %{REQUEST_URI} ^/folder/

like:
RewriteEngine on 
# This will handle any file that ends in php (like index.php)
RewriteCond %{QUERY_STRING} !subdomain=
RewriteCond %{HTTP_HOST} ([^.]+)\.digitalassetbag\.com
RewriteCond %1 !=www
RewriteRule \.php$ /$1?subdomain=%1 [QSA,L]
 
# This will handle URLs like /products
RewriteCond %{REQUEST_URI} !\.php$
# exclude two folders
RewriteCond %{REQUEST_URI} ^/(images|css)/
RewriteCond %{QUERY_STRING} !subdomain=
RewriteCond %{HTTP_HOST} ([^.]+)\.digitalassetbag\.com
RewriteCond %1 !=www
RewriteRule ^/?(.+)/?$ /$1.php?subdomain=%1 [QSA]

Open in new window

0
 

Author Comment

by:SheppardDigital
ID: 24894937
Hi,

When I try that I get this error

"This web page has a redirect loop."
0
 

Author Closing Comment

by:SheppardDigital
ID: 31597222
I just removed the 2nd paragraph and it's all working, thanks
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 24895112
There's a ! (=not) missing, it should read
RewriteCond %{REQUEST_URI} !^/folder/
 
resp.
RewriteCond %{REQUEST_URI} !^/(images|css)/

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

610 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