Page 1 of 1

Mod Rewrite need help

Posted: Fri Aug 11, 2006 4:36 am
by fastfingertips
I would like to redirect all links that has "backend" word in it to the backend.php

My links may look:

http://localhost/backend/group
http://localhost/backend/group/list

Pls i really need help with this issue

Posted: Sat Aug 12, 2006 1:08 am
by RobertGonzalez

Code: Select all

RewriteRule ^(backend).*$ /backend.php [QSA,L]

Posted: Mon Aug 14, 2006 1:11 am
by fastfingertips
Is not working, i got an 500 error :( , i don't know why is keep looping.

The script should not perform redirect if i'm requiring an image, so what is wrong here, especially with the redirect rule?

Code: Select all

RewriteCond  %{REQUEST_URI} !\.(js|ico|gif|jpg|png|css)$ 
RewriteRule ^(backend).*$ /backend.php [QSA,L]

Posted: Mon Aug 14, 2006 1:18 am
by RobertGonzalez
Post your entire .htaccess file.

Posted: Mon Aug 14, 2006 1:20 am
by fastfingertips
This is my htaccess

Code: Select all

RewriteEngine on
RewriteCond  %{REQUEST_URI} !\.(js|ico|gif|jpg|png|css)$ 
RewriteRule ^(backend).*$ /backend.php [QSA,L]
php_value include_path ".;d:/proiecte/proiect/library.;d:/proiecte/proiect"
Looking in error logs:

Code: Select all

[Mon Aug 14 09:18:02 2006] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

Posted: Mon Aug 14, 2006 1:32 am
by RobertGonzalez

Code: Select all

RewriteEngine on
# Im not sure if this one is right or not
RewriteCond  %{REQUEST_URI} !\.(js|ico|gif|jpg|png|css)$ 

# If there is an exact match, skip the next 1 lines
RewriteRule ^.*$ - [S=1]

# If the URI is backend* redirect to backend.php
RewriteRule ^(backend).*$ /backend.php [QSA,L]

# Not sure what this does
php_value include_path ".;d:/proiecte/proiect/library.;d:/proiecte/proiect"

Posted: Mon Aug 14, 2006 1:41 am
by fastfingertips
The problem is that he is trying to get

Code: Select all

D:/proiecte/proiect/document_root/backend
And not the backend.php. I also removed conditions but same problem. Is because QSA is adding backend instead of what i need?

Posted: Mon Aug 14, 2006 1:51 am
by RobertGonzalez
I'm sorry, but I am not sure that I can offer anything else. Not that I don't want to, but I think my expertise in this area is at its end with this particular problem and the rest would be just guessing. Sorry.

Posted: Mon Aug 14, 2006 2:09 am
by fastfingertips
Just a little help if you can, my problem is that if i have that backend i would like to redirect to the backend.php otherwise i would like top redirect to the index.php, which in my case is frontend.

Can you suggest me something? I will make a study on it after.

I succed to create something:

Code: Select all

RewriteCond  %{REQUEST_URI}	 !\.(js|ico|gif|jpg|png|css)$
RewriteRule  ((.*)\/)backend(\/.*)$ backend.php [L]
RewriteRule  !((.*)\/)backend(\/.*)$ index.php [L]
But i don't know why the script is not ending if a backend has been found. It is continuing and is making a redirect to index :(

Posted: Mon Aug 14, 2006 2:15 am
by RobertGonzalez
If it is making it to index, then the regular expression you are using is not working for 'backend'.

Posted: Mon Aug 14, 2006 2:17 am
by fastfingertips
I'm thinking at something like this:

Code: Select all

RewriteEngine on
php_value include_path ".;d:/proiecte/proiect/library.;d:/proiecte/proiect"
RewriteCond  %{REQUEST_URI}	 !\.(js|ico|gif|jpg|png|css)$

RewriteRule ^.*$ index.php [L]
RewriteRule  ^backend\/.*$ backend.php [L]
This id working:

Code: Select all

RewriteEngine on
php_value include_path ".;d:/proiecte/proiect/library.;d:/proiecte/proiect"
RewriteCond  %{REQUEST_URI}	 !\.(js|ico|gif|jpg|png|css)$
RewriteRule  ^backend\/.*$ backend.php [L]
But when i'm adding the index line he is not stoping at backend (if URL has backend inside, it is continuing and redirects me to index) :(

Posted: Mon Aug 14, 2006 2:18 am
by RobertGonzalez
Sorry man, I got no clue.

Posted: Mon Aug 14, 2006 3:41 am
by fastfingertips
Solved, solution is:

Code: Select all

RewriteEngine on
php_value include_path ".;d:/proiecte/proiect/library.;d:/proiecte/proiect"
RewriteCond  %{REQUEST_URI}	 !\.(js|ico|gif|jpg|png|css)$

RewriteRule ^backend\/.*$ backend.php [L,S=1]
RewriteRule ^((?!backend).)*$ index.php [L]

Posted: Mon Aug 14, 2006 3:50 am
by RobertGonzalez
There you go, you added the [S] flag.