Jump to content

[SOLVED] Mod Rewrite alternative?


amwd07

Recommended Posts

I have tried to use htaccess to get the following to work with or without trailing slash

maybe there is another way to do this via PHP ???

 

Currently the following rule works but only without the trailing slash

#RewriteRule ^([^.]+)/([^.]+)$ /dynamic.php?feature=$1&section=$2 [L]

 

www.example.co.uk/$1

www.example.co.uk/$1/$2  /// these 2 work

 

www.example.co.uk/$1/

www.example.co.uk/$1/$2/  /// these ones don't & unfortuntly google results show the trailing slash

 

the error displayed with trailing slash:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

I'm not sure if this is a PHP issue or Htaccess (possibly both?)

previous modrewite post here http://www.phpfreaks.com/forums/index.php/topic,195423.0.html

 

Link to comment
https://forums.phpfreaks.com/topic/104007-solved-mod-rewrite-alternative/
Share on other sites

Thank you for your reply

I have tried doing this but it effects the other rule, but your right it removes the trailing slash but for some reason the dining rule now fails ?

 

#Removes trailing slash from URL

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

 

RewriteRule ^([^.]+)$ /dynamic.php?feature=$1 [L]

 

 

RewriteRule ^([^.]+)/dining dining.php?town=$1 [L]

 

you'll need to move the dining line above the other one because the other one matches anything, so dining will never be reached unless it is first.

 

 

#Removes trailing slash from URL

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

 

RewriteRule ^([^.]+)/dining$ /dining.php?town=$1 [L]

RewriteRule ^([^.]+)$ /dynamic.php?feature=$1 [L]

 

Genius it works  :)

 

the only other small issue is with the bottom 2 lines the first rule works but the second one doesn't ?

 

#Removes trailing slash from URL

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

 

RewriteRule ^([^.]+)/dining$ /dining.php?town=$1 [L]

RewriteRule ^dining/([^.]+)-([^.]+)\.php$ dining.php?county=$1&town=$2 [R,L]

RewriteRule ^([^.]+)/eatingout/([^.]+) eatingout.php?town=$1&accountname=$2 [L]

 

RewriteRule ^([^.]+)$ /dynamic.php?feature=$1 [L]

RewriteRule ^([^.]+)/([^.]+)$ /dynamic.php?feature=$1&section=$2 [L]

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.