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
https://forums.phpfreaks.com/topic/51791-solved-complex-dynamic-mod_rewrite/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.