Announcement

Collapse
No announcement yet.

Remove Trailing Slash / URL using HTACCESS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Remove Trailing Slash / URL using HTACCESS

    Hello,,,


    How I can browse a page without slash

    Adding or removing a trailing slash to all URLs of this site returns an error page (404). This is OK as no content is being duplicated, but visitors might try browsing to the pages of this website with or without a trailing slash. Ideally, the alternate URL should redirect to the correct page.
    ​​​​​​​
    LIKE:

    https://www.xvids.cc/video/amateur-t...ies-best-ever/
    https://www.xvids.cc/video/amateur-t...cies-best-ever

    https://www.xvids.cc/latest-updates/
    https://www.xvids.cc/latest-updates


    Code:
    RewriteRule ^videos/([0-9]+)/([^/]+)/$ /view_video.php?id=$1&dir=$2 [L,QSA]
    RewriteRule ^videos/([^/]+)/$ /view_video.php?dir=$1 [L,QSA]
    
    RewriteRule ^latest-updates/([0-9]+)/$ /videos_list_latest.php?from=$1 [L,QSA]
    RewriteRule ^latest-updates/$ /videos_list_latest.php [L,QSA]
    
    RewriteRule ^top-rated/([0-9]+)/$ /videos_list.php?sort_by=rating&from=$1 [L,QSA]
    RewriteRule ^top-rated/$ /videos_list.php?sort_by=rating [L,QSA]
    
    RewriteRule ^most-popular/([0-9]+)/$ /videos_list.php?sort_by=video_viewed&from=$1 [L,QSA]
    RewriteRule ^most-popular/$ /videos_list.php?sort_by=video_viewed [L,QSA]
    
    RewriteRule ^categories/([0-9]+)/$ /categories_videos.php?from=$1 [L,QSA]
    RewriteRule ^categories/$ /categories_videos.php [L,QSA]
    RewriteRule ^categories/([^/]+)/([0-9]+)/$ /videos_list.php?category=$1&from=$2 [L,QSA]
    RewriteRule ^categories/([^/]+)/$ /videos_list.php?category=$1 [L,QSA]
    Thanks

  • #2
    The only good way I know is to duplicate each rule with 301 redirect.

    Sample rules:
    Code:
    RewriteRule ^latest-updates/([0-9]+)/$ /videos_list_latest.php?from=$1 [L,QSA]
    RewriteRule ^latest-updates/$ /videos_list_latest.php [L,QSA]
    Add redirect rules without / at the end:
    Code:
    RewriteRule ^latest-updates/([0-9]+)$ /latest-updates/$1/ [R=301,L]
    RewriteRule ^latest-updates$ /latest-updates/ [R=301,L]
    This should redirect:
    http://domain.com/latest-updates -> 301 -> http://domain.com/latest-updates/
    http://domain.com/latest-updates/2 -> 301 -> http://domain.com/latest-updates/2/
    http://domain.com/latest-updates/3 -> 301 -> http://domain.com/latest-updates/3/
    etc.

    I have also seen some generic redirects, which were claimed to redirect all URLs automatically, however they should also consider filenames and do not force redirect for files. This is dangerous practice, as it can lead to some functionality not working. You can find those in google:
    https://www.google.com/search?q=mod_...ash+to+all+url s

    My opinion is better not to use it.

    Comment


    • #3
      Hi

      I had created a ticket for about this question
      Answer is: Just the
      Code:
      ?
      But where adding this ? I don't know

      More example:

      this is facebook page
      If I Type https://www.facebook.com/4XVIDS
      OR https://www.facebook.com/4XVIDS/

      Both URL working Without /

      Comment


      • #4
        xvids: sorry, your first account was removed by mistake when cleaning spammer accounts.

        Originally posted by xvids View Post
        I had created a ticket for about this question
        Do you mean you have created support ticket now? We do not see any ticket from you...

        If you want to make both URLs accessible without 301 redirect, then it is even easier, you can add ? at the end of every rule which ends with /.

        Example:
        Code:
         
        RewriteRule ^latest-updates/([0-9]+)/$ /videos_list_latest.php?from=$1 [L,QSA] 
        RewriteRule ^latest-updates/$ /videos_list_latest.php [L,QSA]
        Changed:
        Code:
         
        RewriteRule ^latest-updates/([0-9]+)/?$ /videos_list_latest.php?from=$1 [L,QSA]
        RewriteRule ^latest-updates/?$ /videos_list_latest.php [L,QSA]
        You can find such places by searching for /$ - almost every rule in .htaccess ends with that. So you can batch replace with /?$
        But please make a backup of .htaccess before applying batch replace to it.

        This will mean that both will work:
        http://domain.com/latest-updates/
        http://domain.com/latest-updates

        The only possible issue is content duplication, however by default theme should display canonical URL for every page, so there won't be duplication.

        Comment


        • #5
          Thanks Its working perfect

          Comment

          Working...
          X