SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    May 2007
    Location
    West Coast
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trailing Slash Removal - help

    I want to remove ALL trailing slashes on file names, NOT directories on a php driven site

    How to do that? As I have tried multiple htaccess edits and none work

    Code:
    latest is   RewriteCond %{HTTP_HOST} ^(www.)?mywebsite\.com$ [NC]
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
    and I did change website to mine

    The site is designed as follow

    1. each page name has a folder page1... > index.php inside which calls includes files header.php, footer.php, navbar.php and > contents folder > page1.php


    SAMPLE of page1.index.php file
    Code:
    <?php 
      // Edit the following three lines of code. '$a' adjusts the relative paths of the page. '$current" tells the Nav Bar what the current page is. '$thisPageContent'  match the filename in the includes > 6.content folder.
    	$a = '../';
    	$current = 1;
    	$thisPageContent = 'page1.php';
    	
    	// Do not change the following line of code. You can go into the '0.seo.php' file to edit SEO content.
    	include ($a . 'includes/0.seo.php');
    	
    	// Edit the following three lines of code. You will want to match the variables after the equals sign to the variables in '0.seo.php'.
    	$thisPageTitle = $page1Title;
    	$thisPageKeywords = $page1keywords;
    	$thisPageDescription = $page1Description;
    ?>
    
    <?php
    	
    	include ($a . 'includes/1.doctype.php');
    ?>
    <head>
    <?php include ($a . 'includes/2.header.php'); ?>
    
      <title><?=$thisPageTitle?></title>
    		
      <meta name="keywords" content="<?=$thisPageKeywords?>">	
      <meta name="description" content="<?=$thisPageDescription?>">
      
    </head>
    
    <body>
    
    <?php 
      include ($a . 'includes/3.top.php'); 
      include ($a . 'includes/4.navbar.php'); 
      include ($a . 'includes/6.content/' . $thisPageContent ); 
      include ($a . 'includes/7.footer.php'); 
    ?>
    
    </body>
    </html>
    The problem is every single page has a trailing slash behind it, directories and normal page names.

    I want www.website.com/page1/
    to be
    www.website.com/page1

    and this solution did not work:

    1.
    RewriteCond %{HTTP_HOST} ^(www.)?mywebsite\.com$ [NC]
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

    2. RewriteRule ^(.*)/+$ $1 [R=301,L]


    htaccess

    Code:
    # -FrontPage-
    
    IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
    
    <Limit GET POST>
    order deny,allow
    deny from all
    allow from all
    </Limit>
    <Limit PUT DELETE>
    order deny,allow
    deny from all
    </Limit>
    AuthName site.com
    AuthUserFile /home/bolo/public_html/_vti_pvt/service.pwd
    AuthGroupFile /home/bolo/public_html/_vti_pvt/service.grp
    
    ErrorDocument 404 http://www.site.com/404
    
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^site.com
    RewriteRule (.*) http://www.site.com/$1 [R=301,L]
    
    order allow,deny
    deny from
    94.100.22.210 
    213.238.175.8
    188.143.232.31 
    188.143.232.111
    allow from all
    
    
    <IfModule mod_expires.c>
    
    # Enable expirations
    ExpiresActive On
    
    # Default directive
    ExpiresDefault "access plus 1 month"
    
    # My favicon
    ExpiresByType image/x-icon "access plus 1 year"
    
    # Images
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    
    # CSS
    ExpiresByType text/css "access 1 month"
    
    # Javascript
    ExpiresByType application/javascript "access plus 1 year"
    
    </IfModule>
    and I don't know why FrontPage is in there at the top for this site.

  2. #2
    SitePoint Addict
    Join Date
    May 2007
    Location
    West Coast
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I realize it is a php diven site.. it fetches includes files and content > page1.php ut if there is a way Wordpress can do this, is there not a similar way for one customly built?

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    lukkas,

    What you're trying to do is:

    If the URI is not a directory
    Redirect removing any trailing slash.

    Hmmm, that sounds like

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ $1 [R=301,L]
    Quote Originally Posted by lukkas
    Code:
    latest is   RewriteCond %{HTTP_HOST} ^(www.)?mywebsite\.com$ [NC]
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
    You only need the RewriteCond if you're sharing the directory with another domain (which you don't want to redirect).

    Whew! Rather than code all that in PHP, removing the trailing / will resolve your relative link problems! (It looks like you're trying to use PHP to undo poor links, i.e., with trailing /'s, rather than generate good links). If you still have a problem with relative links, use the <BASE> tag I reference in my signature's tutorial to set the directory level (location of index.php in your directory structure).

    Regards

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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