Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 12th Aug 2014, 08:33 PM   #1
HyperActive Warrior
War Room Member
 
Lukas's Avatar
 
Join Date: 2006
Location: , , .
Posts: 342
Thanks: 22
Thanked 11 Times in 10 Posts
Default
htaccess remove extension, same name for page and folder
Share on: 
fb share twitter share gplus share more share

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]
Lukas is offline  
Unread 13th Aug 2014, 03:09 AM   #2
Active Warrior
 
minirich's Avatar
 
Join Date: 2014
Location: Austria, Vienna
Posts: 52
Thanks: 16
Thanked 10 Times in 10 Posts
Default
Re: htaccess remove extension, same name for page and folder
Share on: 
fb share twitter share gplus share more share

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
minirich is offline  
Unread 13th Aug 2014, 03:11 AM   #3
Active Warrior
 
minirich's Avatar
 
Join Date: 2014
Location: Austria, Vienna
Posts: 52
Thanks: 16
Thanked 10 Times in 10 Posts
Default
Re: htaccess remove extension, same name for page and folder
Share on: 
fb share twitter share gplus share more share

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
minirich is offline  
Unread 13th Aug 2014, 07:21 AM   #4
HyperActive Warrior
War Room Member
 
Lukas's Avatar
 
Join Date: 2006
Location: , , .
Posts: 342
Thanks: 22
Thanked 11 Times in 10 Posts
Default
Re: htaccess remove extension, same name for page and folder
Share on: 
fb share twitter share gplus share more share

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
Lukas is offline  
Unread 14th Aug 2014, 12:46 AM   #5
Active Warrior
 
minirich's Avatar
 
Join Date: 2014
Location: Austria, Vienna
Posts: 52
Thanks: 16
Thanked 10 Times in 10 Posts
Default
Re: htaccess remove extension, same name for page and folder
Share on: 
fb share twitter share gplus share more share

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
minirich is offline  
Closed Thread


Bookmarks

Tags
extension, folder, htaccess, page, remove


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 02:05 AM.