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

PHP Templating with Twig Templating Languages Adding a Second Page

Shoko Ishigaki
Shoko Ishigaki
21,826 Points

.htaccess file

I couldn't find the .htaccess file in the teacher's notes or in the downloaded project folder. I pasted below which is from "Introducing MVC Frameworks in PHP" course, but was not sure if this is what should be in the .htaccss file for this lesson.

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

3 Answers

Darrell Conklin
seal-mask
.a{fill-rule:evenodd;}techdegree
Darrell Conklin
Python Development Techdegree Student 22,377 Points

The .htaccess file was not named

_htaccess

so the file is hidden. If you open your console and make your way to the downloaded "starter_files" folder and use the command ls -a you will see that the .htaccess file is there. Assuming you're on a mac and not a windows machine.

Alternatively you could:

In macOS Sierra Apple added a Finder keyboard shortcut that makes it possible to quickly show all the hidden files and folders. You just need to do the following:

  1. Open the Finder
  2. Go to your Macintosh HD folder (access this from Devices in the left column)
  3. Hold down Cmd + Shift + . (dot)
  4. All the hidden files will become visible
  5. Hold down Cmd + Shift + . (dot) a second time to hide the files again

If you are on a windows machine:

  1. Open File Explorer from the taskbar.
  2. Select View > Options > Change folder and search options.
  3. Select the View tab and, in Advanced settings, select Show hidden files, folders, and drives and OK.
Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

In case this helps anyone in any way this is the version of the .htaccess file (which was not a hidden file in my version of the downloads.

<IfModule mod_rewrite.c>
  RewriteEngine On

  # Some hosts may require you to use the `RewriteBase` directive.
  # Determine the RewriteBase automatically and set it as environment variable.
  # If you are using Apache aliases to do mass virtual hosting or installed the
  # project in a subdirectory, the base path will be prepended to allow proper
  # resolution of the index.php file and to redirect to the correct URI. It will
  # work in environments without path prefix as well, providing a safe, one-size
  # fits all solution. But as you do not need it in this case, you can comment
  # the following 2 lines to eliminate the overhead.
  RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
  RewriteRule ^(.*) - [E=BASE:%1]

  # If the above doesn't work you might need to set the `RewriteBase` directive manually, it should be the
  # absolute physical path to the directory that contains this htaccess file.
  # RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>

This is the one I used but my routes aren't working. It is showing the same content whether it's using the home or the contact route. I'm a bit lost to say the least.

I haven't been able to make the routing work. I'm on a free trial. Won't be going any further with Treehouse.