htaccess remove extension, same name for page and folder

by Lukas
4 replies
How do I solve the following. ?

Code:
www.example.com/tires

www.example.com/tires/slicks
I have got the .php extension to not display.

When I click on the slicks page on a breadcrumb to "tires" it shows example.com/tires/ instead of .com/tires and then the links on the page become messed up.

How do I make it work all the way around?

I have seen it working flawlessly on a few other sites


here is my current htaccess

Code:
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>

Options +FollowSymLinks

ErrorDocument 404  /404/

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.htm HTTP/
RewriteRule ^index.htm$ http://www.example.com/ [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.php HTTP/
RewriteRule ^index.htm$ http://example.com/ [R=301,L]

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.example.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+).php([#?][^ ]*)? HTTP/
RewriteRule ^(.+).php$ http://www.example.com/$1 [R=301,L]

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
#extension #folder #htaccess #page #remove
  • Profile picture of the author minirich
    Hi, I am a bit confused by your examples, and by the redundancy in your htaccess.
    What I understand you want to achieve is the following:
    Code:
    http://www.example.com/tires    -> www.example.com/tires/index.html
    http://www.example.com/tires/slicks -> www.example.com/tires/slicks.html
    is this correct.

    as an improvement you can add this line
    Code:
    RewriteEngine on
    RewriteBase /
    Then you could work with relative paths form the route dir.

    You could get rid of all the domain names in the rules/coditions expect you really want to redirect to a different server.

    If you leave the R=301 in the flags of the rewrite rules the user will see the url change in his browser, as the browser will be notified that the resource has changed the location.
    If you want to make it silent (invisible to the user) remove all the R=... flags from the Rules.

    Hope that helps
    Mike
    {{ DiscussionBoard.errors[9438300].message }}
  • Profile picture of the author minirich
    Hi, I am a bit confused by your examples, and by the redundancy in your htaccess.
    What I understand you want to achieve is the following:
    Code:
    http://www.example.com/tires    -> www.example.com/tires/index.html
    http://www.example.com/tires/slicks -> www.example.com/tires/slicks.html
    is this correct.

    as an improvement you can add this line
    Code:
    RewriteEngine on
    RewriteBase /
    Then you could work with relative paths form the route dir.

    You could get rid of all the domain names in the rules expect you really want to redirect to a different server.

    If you leave the R=301 in the flags of the rewrite rules the user will see the url change in his browser, as the browser will be notified that the resource has changed the location.
    If you want to make it silent (invisible to the user) remove all the R=... flags from the Rules.

    Hope that helps
    Mike
    {{ DiscussionBoard.errors[9438305].message }}
    • Profile picture of the author Lukas
      Originally Posted by minirich View Post

      Hi, I am a bit confused by your examples, and by the redundancy in your htaccess.
      What I understand you want to achieve is the following:
      Code:
      http://www.example.com/tires    -> www.example.com/tires/index.html
      http://www.example.com/tires/slicks -> www.example.com/tires/slicks.html
      is this correct.

      as an improvement you can add this line
      Code:
      RewriteEngine on
      RewriteBase /
      Then you could work with relative paths form the route dir.

      You could get rid of all the domain names in the rules expect you really want to redirect to a different server.

      If you leave the R=301 in the flags of the rewrite rules the user will see the url change in his browser, as the browser will be notified that the resource has changed the location.
      If you want to make it silent (invisible to the user) remove all the R=... flags from the Rules.

      Hope that helps
      Mike
      No, these work fine.

      Code:
      www.example.com/tires
      
      www.example.com/tires/slicks
      
      what doe snot work now is
      
      when you are on this page -- > www.example.com/tires/slicks and click the link to go back to 
      www.example.com/tires  ,
       it takes you to www.example.com/tires/  when it should be just www.example.com/tires a separate page
      
      the site is in php, not .html
      {{ DiscussionBoard.errors[9438893].message }}
      • Profile picture of the author minirich
        Can you turn on the rewrite log.
        By adding these lines
        Code:
        RewriteLog "PATH_TO_LOG_LOCATION/rewrite.log"
        RewriteLogLevel 3
        After the problem is logged or resovled, remove these lines again, they can cause a severe slowdown of your webserver.

        Mike
        {{ DiscussionBoard.errors[9440999].message }}

Trending Topics