Mod Rewrite need help

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Mod Rewrite need help

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

RewriteRule ^(backend).*$ /backend.php [QSA,L]
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post 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]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Post your entire .htaccess file.
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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"
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post 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 :(
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If it is making it to index, then the regular expression you are using is not working for 'backend'.
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post 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) :(
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sorry man, I got no clue.
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post 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]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

There you go, you added the [S] flag.
Post Reply