Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    191
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Removing the trailing slash?

    Hi, wondering how I can remove the trailing slash on the URLs being rewritten? Not clear on why all the URLs I'm working with end with a trailing slash.

    Code:
    RewriteEngine On
    RewriteRule ^category/([a-z0-9_-]+)/$ /category/category.cfm?fileName=$1&ses=1 [PT,L]

  • #2
    New Coder
    Join Date
    Jan 2011
    Posts
    75
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Well with what I'm familiar with it's probably because server may of read it as a folder.

    Since I tested it, the page the user requests gets sent to your server, then your server reads the page and if it's a folder, it gives a trailing slash, if it's a file, then it will give it the file page unless you rewrite mod to remove file extensions.

    Example: if I have a folder named php and let's say a user access the page this way.

    http://yourwebsite.com/testingfolder/php

    If php is a folder, then it'll end up going to

    http://yourwebsite.com/testingfolder/php/

    If it's a file for example php.php

    then it'll end up going to

    http://yourwebsite.com/testingfolder/php.php

    Unless you rewrite the mod to remove the .php extension,

    then it'll end up going to

    http://yourwebsite.com/testingfolder/php

    But that is just all an example, it's sort of answering your question why your webpages keeps ending up with trailing slashes.
    But since you given a code, just remove the trialing slash in RewriteRule ^category/([a-z0-9_-]+)/$
    It's because you have a trialing slash right here /([a-z0-9_-]+)/$ which is probably why you keep getting trialing slashes in your URL.

    Sorry if it's not much help.

  • Users who have thanked xiong_ster123 for this post:

    wyclef (09-23-2013)

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    191
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Ah! Thank you so much.

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    191
    Thanks
    6
    Thanked 0 Times in 0 Posts
    i'm curious, is there a way to set it so it can both have the trailing slash and not have the trailing slash? this seems to work but is this the correct way?

    Code:
    RewriteEngine On
    RewriteRule ^category/([a-z0-9_-]+)$ /category/category.cfm?fileName=$1&ses=1 [PT,L]
    RewriteRule ^category/([a-z0-9_-]+)/$ /category/category.cfm?fileName=$1&ses=1 [PT,L]
    Last edited by wyclef; 09-23-2013 at 04:57 PM.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You should be able to simply add a ? after the last /. The ? is equivalent to 0 or 1. Saves the trouble of multiple rewrite conditions.

    I haven't a clue what the other poster is talking about there. Unless you have explicit rules to govern this, if I go here:
    http://yourwebsite.com/testingfolder/php/
    Than this won't resolve to a file under http://yourwebsite.com/testingfolder/php.php. That will resolve to http://yourwebsite.com/testingfolder/php/index.php.

    As for removing them, don't bother. That has no problem with or without the trailing slash except for with the ruleset governing them. The links you have were specified to have the trailing slash, that isn't done with the mod_rewrite. All that you want to do is make sure that the trailing slash is optional.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    Regular Coder
    Join Date
    Feb 2005
    Posts
    191
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Perfect. Thanks!
    Code:
    RewriteEngine On
    RewriteRule ^category/([a-z0-9_-]+)/?$ /category/category.cfm?fileName=$1&ses=1 [PT,L]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •