Jump to content

adding trailing slash


phpnewby1918

Recommended Posts

Hello,

 

i've been making this project in my spare time, haven't looked at it for a while. But i have some spare time so i'm going to dip my toe again.

 

I have been using the following .htaccess rules

 

RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f   
RewriteRule ^about/?$ about.php 
RewriteRule ^about/([A-Za-z\+\-]+)/?$ ./about.php?x=$1  

 

 

Which achieves what I wanted (initially). In that I wanted to be able to make these URLs:

www.example.com/about.php
www.example.com/about.php?x=jonathon

 

 

 

Become these URLs respectively:

www.example.com/about
www.example.com/about/jonathon

 

 

Which once i'd fiddled around and achieved it, I was pretty happy with. Obviosuly this meant some changes to my relative CSS paths, which was a bit fiddly, but I couldn't see a better way around it. Though if you know any good ideas, please let me know.

 

My scenario now is much as I enjoy that these URLs look prettier, there are 2 problems with them.

 

1 - if someone types

www.example.com/about/

for example, the css relative paths fail. So the paages aren't styled.

 

2 - Also in terms of seo it looks like duplicate content

 

Sooo, my next thought was to automatically append the trailing slash, so that

^about

becomes

^about/

and

^about/jonathon

becomes

^about/jonathon/

 

auomatically. Therefore stopping a duplicate content problem and also meaning that my css will render properly.

 

So far reading around the many many articles and examples i've seen before i've come up with this:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://localhost/www.example.co.uk/$1/ [L,R=301] 

 

 

Which works in that 'about' does indeed become 'about/' and 'about/jonathon' does becomes 'about/jonathon/'

 

Regrettably, I always get a object not found 404 error! :mellow:

 

Which is not the desired effect, I am not particulary good, (in fact i'm not even remotely good at .htaccess) so can anyone help me out with this conundrum. I have been clearing my browser cache regulary as I tinker with it to make sure that it always using the most up to date .htaccess file.

 

Thanks in advance

 

Jonathon B)

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.