help with RewriteCond and rewriterule

Alles, was den Apache betrifft, kann hier besprochen werden.

help with RewriteCond and rewriterule

Postby avk » 07. July 2019 04:51

Hi, I have been going crazy trying to figure this out.

lets say I have an incoming request site.com/en/resources/help.jpg

I would like to test if the file exists by ignoring the the /en part. /en folder is not present in documentroot.

Below works only if there is an en folder. Is there way to remove /en part and then test if a file exists?

Code: Select all
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ http://localhost:3000/$1 [P,L]


I did try to experiment with expressions and If module but cant get it working.
avk
 
Posts: 2
Joined: 07. July 2019 04:49
XAMPP version: 2.4
Operating System: linux

Re: help with RewriteCond and rewriterule

Postby Nobbie » 07. July 2019 20:55

What is the idea of your very odd RewriteCond? Show some working examples that fits to these Conditions.
Nobbie
 
Posts: 11149
Joined: 09. March 2008 13:04

Re: help with RewriteCond and rewriterule

Postby avk » 08. July 2019 02:08

Iam trying to route traffic to nodejs but use apache to serve static content. the reason /en in url is important is because nodejs understands it for localization and serve language specific content. it could change to /es,/fr.

example: site.com/en/resources/help.jpg -- search for a valid file in DocumentRoot by ignoring the /en part. got this to work. if found return file and complete request.
site.com/en/resources/assistant -- this is not a valid file reference then send this to proxy with the /en part.
avk
 
Posts: 2
Joined: 07. July 2019 04:49
XAMPP version: 2.4
Operating System: linux

Re: help with RewriteCond and rewriterule

Postby Nobbie » 08. July 2019 13:34

Sorry, but i cannot follow your example. The "DocumentRoot" is the PHYSICAL Name of the folder, which stores the top level files of a Domain. For example, the DocumentRoot of Xampps localhost (Domain) is c:/xampp/htdocs. A valid URL looks like http://localhost/en/index.html

Where is the "DocumentRoot" (c:/xampp/htdocs) in the URL, which is evaluated by your expression?? Why do you look for "c./xampp/htdocs" in a valid URL?? Is there "c:/xampp/htdocs" in "http://localhost/en/index.php"??
Nobbie
 
Posts: 11149
Joined: 09. March 2008 13:04


Return to Apache

Who is online

Users browsing this forum: No registered users and 3 guests