Forum Moderators: phranque

Message Too Old, No Replies

Complex rewrite rule

More than 1 rewrite rule

         

virtuals

6:09 pm on Jun 5, 2006 (gmt 0)

10+ Year Member



Hi

I have discussed this before and as was recommended I changed my host.

What I'm trying to do is:

1. Redirect non-www domains to www domains

2. Remove index.php from all urls

3. Add trailing slash to url if missing

This is what I'm using write now [thanks to Jim]

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI}!(\.[^/]+¦/)$
RewriteRule (.+) /$1/

RewriteCond %{HTTP_HOST}!^www.
RewriteRule (.*) [%{HTTP_HOST}...] [R=301,L]

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule (.*) index.php?$1 [L]

----
The trailing slash is not being added. This is the issue now.

http:/example.com/a/b

Redirects to

http:/www.example.com/a/b

Not

http:/www.example.com/a/b/

Warm Regards

virtuals

7:28 pm on Jun 5, 2006 (gmt 0)

10+ Year Member



Ok this one seems to work better,

Would someone please correct any posible mistakes in this?

RewriteEngine on
RewriteBase /

RewriteRule ^([^\.]+[^/])$ [%{HTTP_HOST}...] [L]

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule (.*) index.php?$1 [L]

RewriteCond %{HTTP_HOST}!^www\.
RewriteRule ^(.*)$ [%{HTTP_HOST}...] [R=301,L]

virtuals

1:50 pm on Jun 8, 2006 (gmt 0)

10+ Year Member



The code above (in my last reply) works fine exept for adding the traling slash when the www is present in the url.

http://example.com/a/b

redirects to

http://www.example.com/a/b/

but

http://www.example.com/a/b

remains as it is.

I apriciate any help

jdMorgan

9:19 pm on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have multiviews enabled?

If so, add


Options -MultiViews

and see if that helps.

Jim