Forum Moderators: phranque
My site is a PHP dadabase driven site where all files should end without the /
i.e. example.co.uk/insurance/cheap
However example.co.uk/insurance/cheap/ also works and so duplicate content could be an issue. I would like the trailing slash to be diverted to the non trailing slash, or if it is better, the other way round.
I am well aware this question has been asked many times and I have scanned through many old posts.
I understand what the code will do, but I am not a coder and just get confused when it is all explained to me.
My solution has been to read the posts and copy and paste as many mod rewrite code into my .htaccess file until I find one that works and have done this for non www to www and index to / issues which work ok.
But even looking at past posts I cant find a version that works.
So i am posting my .htaccess (minus real url) to see if the existing version is affecting any more additions or if someone can give me another version of the rewrite that may work. can you help?
here is my current .htaccess. What can I add to send / to non /
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(example\.co(\.uk¦m)¦www\.example\.com) [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index.php$ http://www.example.co.uk/$1 [R=301,L]
# Is it not a file
RewriteCond %{REQUEST_FILENAME} !-f
# Is it not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ manager.php?url=$1 [L]
What can i add to this?
Thanks
Mark
[edited by: jdMorgan at 9:25 pm (utc) on Sep. 30, 2007]
[edit reason] example.com, example.co.uk [/edit]
So are you saying I have to do this per every URL link to my site that ends in a "/"?
I was hoping for some code for my .htaccess so no matter who links to me and if they link using the "/" it will automatically redirect.
As i said in the previous post, I dont understand the code, just want some help, so i can add whetever will do the job
Mark
I understand what you are saying but just dont have the knowledge to make the complete 2 lines up.
I just want and example of the the 2 lines to try.
The examples i have tried from previous posts have not worked.
I have now swapped the index part over, so it now first.
Mark
Both versions do nothing, as if it wasn't there
RewriteCond %{REQUEST_URI}!^[^.]*/$
RewriteRule (.+) /$1/ [R=301,L]
and
RewriteRule %{REQUEST_FILENAME} index.php [L,NC]
RewriteRule ^(([^/]+/)*([^./]+))/?$ index.php?x=$1 [L]
The content is databased driven, not real pages ans all finsh non slash
Mark
Now that we have some example code to work with, here is how I would suggest modifying it, along with line-by-line comments that, in conjunction with the documents cited in our Charter, may aid in understanding it.
# If requested URI contains no periods or slashes in final path-part
RewriteCond %{REQUEST_URI} !^/([^/]+/)*[^./]+$
# Externally redirect to append a slash
RewriteRule (.+) http://www.example.co.uk/$1/ [R=301,L]
Thanks for the reply.
I am sorry I have broken some sort of charter.
The bottom line is I am pretty good at SEO but can never get my head around any coding, thats a fact.
I have tried this variation of code but does not work as it leaves bare pages with just the words, it takes away the design of the site.
Time to give it up here.
Thanks again
mark