Jump to content

[SOLVED] Complex dynamic mod_rewrite


Recommended Posts

I will attempt to present the problem in the simplest way possible.

 

Desired result (to work dynamically with any string)

 

URL

address bar

physical page

 

home

home/

domain.com/index.php?x=home

 

home/

home/

domain.com/index.php?x=home

 

images/logo.gif

images/logo.gif

images/logo.gif

 

The rules in words

 

1. Where there is a slash at the end, redirect [working]

2. Where there is no slash or dot in the URI, add a trailing slash

3. Where there isn't a file or directory existing, redirect

 

Working

 

1. RewriteRule ^(.+)/$ http://findanecohome.co.uk/index.php?x=$1 [nc,qsa]

 

Attempts

 

2. RewriteRule ^((.+)!\.(.+))/$ http://findanecohome.co.uk/$1/ [nc,r,qsa]

 

3. RewriteCond %{REQUEST_URI} !-f
    RewriteCond %{REQUEST_URI} !-d
    RewriteCond ^(.+)$ http://findanecohome.co.uk/index.php?x=$1 [nc,qsa]

Link to comment
Share on other sites

Gargh! You work on something for two days, post it on a forum and work it out 5 minutes later. *sigh*

 

Anyway, this is the final solution:

 

RewriteRule ^([A-Za-z0-9-]+)$ http://domain.co.uk/$1/ [are,l,nc,qsa]
RewriteRule ^([A-Za-z0-9-]+)/$ http://domain.co.uk/index.php?x=$1 [l,nc,qsa]

 

I think it meets all the rules.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.