Newbie needs help redirecting index.php in root & subdir

Discuss practical ways rearrange URLs using mod_rewrite.

Newbie needs help redirecting index.php in root & subdir

Postby antmeeks » Tue Sep 23, 2008 11:34 am

I have 2 related problems I'm trying to work into one solution:

EX. 1
domain.com/param1/param2/param3/etc.
SENDS THE SERVER TO:
domain.com/index.php/param1/param2/param3/etc.

AND EX. 2
domain.com/DIRNAME/param1/param2/param3/etc.
SENDS THE SERVER TO:
domain.com/DIRNAME/index.php/param1/param2/param3/etc.

I want to have both these rewrites in one .htaccess, at the root of the site. They need to be able to work for any domain and any dir name. I have a working solution for each scenario, but I can't get both to work together:

Solution For EX. 1:
Code: Select all
RewriteRule ^(.*)$ index.php/$1 [L]


Solution For EX. 2:
Code: Select all
RewriteRule ^([^/]+)/?([^/]+) $1/index.php/$2 [L]


My instinct is that I need to add some conditional processing... But I can't figure out how to do that (after 4 hours Googling) and I admit, I know nothing about mod_rewrite. There might be an easier way to accomplish this anyway - I'm hoping someone here can help... Thanks in advance!
antmeeks
 
Posts: 4
Joined: Tue Sep 23, 2008 11:29 am
Location: Atlanta

Postby richardk » Tue Sep 23, 2008 12:13 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/$1/ -d
RewriteRule ^([^/]+)(/(.*))?$ /$1/index.php/$3 [QSA,L]

RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby antmeeks » Tue Sep 23, 2008 12:26 pm

richardk wrote:Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/$1/ -d
RewriteRule ^([^/]+)(/(.*))?$ /$1/index.php/$3 [QSA,L]

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


No go, unfortunately.. I get an Apache error.
antmeeks
 
Posts: 4
Joined: Tue Sep 23, 2008 11:29 am
Location: Atlanta

Postby richardk » Tue Sep 23, 2008 12:32 pm

What does your error log say?
Try removing the Options line.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby antmeeks » Tue Sep 23, 2008 12:38 pm

richardk wrote:What does your error log say?
Try removing the Options line.


Apache error:
[Tue Sep 23 16:31:34 2008] [error] [client ::1] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary., referer: http://caanopidev:8888/

Also, I tried removing the options line... didn't work.

The following line works fine by itself for "domainname/dirname/index.php/param/" but not for "domainname/index.php/param/" AND throws the error when the other code is added:

Code: Select all
RewriteCond %{DOCUMENT_ROOT}/$1/ -d
RewriteRule ^([^/]+)(/(.*))?$ /$1/index.php/$3 [QSA,L]
antmeeks
 
Posts: 4
Joined: Tue Sep 23, 2008 11:29 am
Location: Atlanta

Postby richardk » Wed Sep 24, 2008 12:05 pm

Right.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{DOCUMENT_ROOT}/$1/ -d
RewriteRule ^([^/]+)(/(.*))?$ /$1/index.php/$3 [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

This is what I was looking for

Postby antmeeks » Wed Sep 24, 2008 1:11 pm

Just an FYI - Thanks to everyone who tried to help!

Code: Select all
RewriteEngine On

# RULE 1 -
# this is for the sub dir -----------------------------------
RewriteCond %{DOCUMENT_ROOT}/$1/ -d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)(/(.*))?$ /$1/index.php/$3 [L]

# RULE 2 -
# this is for the root dir ----------------------------------
RewriteCond %{DOCUMENT_ROOT}/$1/ !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)(/.*)?$ /index.php/$1$2 [L]
antmeeks
 
Posts: 4
Joined: Tue Sep 23, 2008 11:29 am
Location: Atlanta


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron