Jump to content

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]

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.