Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Steven Burgess](https://secure.gravatar.com/avatar/9037257c8924de75514a5a14646e3432?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Steven Burgess
Courses Plus Student 5,624 PointsRewrite Rule will not work
I'm using A Small Orange to host the site, but I can't get the Rewrite Rule to work at all like in the video... I've tried everything and looked at a lot of resources, but I can't get it to work at all. I know the Rewrite is enable because this code does something
RewriteRule ^(.*)/$ /$1.php [L]
But I can't get this to work for the life of me.
RewriteEngine On RewriteRule ^shirts/$ shirts/shirts.php
1 Answer
![Ron McCranie](https://secure.gravatar.com/avatar/daf02aa9bf168737d31e032fd83599a7?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ron McCranie
7,837 PointsI think what you're looking for is this:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
The rewrite will make sure the 2 conditions are met before using the rule. So first it looks to see if the REQUEST_FILENAME
is not a directory (!-d) then moves to the next condition. The second condition checks to see if the the DOCUMENT_ROOT
(everything before the last slash) plus the filename with a php extension exists, if that's true it moves on to the rule. The rule states that we want to take everything before the last slash and keep it the same, then take the text after the last slash and add a .php
extension.
Steven Burgess
Courses Plus Student 5,624 PointsSteven Burgess
Courses Plus Student 5,624 PointsThis is my first time using the forum function or I would have added some more background.
What I'm trying to do is have someone who goes to site/projects/store/shirts to be directed to site/projects/store/shirts/shirts.php
However in the url bar I want it to still show site/projects/store/shirts
Also, when I add that code to .htaccess it doesn't appear to do anything. Does it matter which director .htaccess is in?
This is the code the video tells me I should have, but it doesn't do anything