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 trialByron Anderson
7,009 Pointspublishing the .htaccess file
Hello again,
I'm having an issue that I think is related to the .htaccess file in the shirts4mike directory I'm trying to publish to.
I'm including a few links as well as the content of my current .htaccess file. You will notice that manually typing in "shirts.php" to the end of the URL(**see next) gets you to the page properly, but
**the navigation link to shirts and the result of clicking a "view (shirt) details" link take you to a 404 error. This, I suspect, is due to some modifications that must be made to the .htaccess file.
here is the URL to the main "index.php" in the "shirts4mike" sub-directory I have published to my server:
<strong>http://www.heartelements.net/shirts4mike</strong>
here is the URL resulting from clicking on any of the links related to SHIRT products (which returns a 404):
<strong>http://www.heartelements.net/shirts4mike/shirts/</strong>
finally, here is the URL to the published shirt page
<strong>http://www.heartelements.net/shirts4mike/shirts/shirts.php</strong>
This is the code in the .htaccess file as per directions from Randy - which all worked well and good in the htdocs directory on my localhost site, no problem (no problem even when files & folders were transferred to a subfolder within that htdocs location)
RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1
RewriteRule ^receipt.php$ /receipt/ [R=301]
RewriteRule ^contact.php$ /contact/ [R=301]
RewriteRule ^shirts.php$ /shirts/ [R=301]
RewriteRule ^(shirts/[0-9]+)$ /$1/ [R=301]
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^shirt.php$ /shirts/%1/? [R=301]
I hope someone has some ideas about this,
Thank You!
2 Answers
William LaMorie
11,769 PointsHey! If you're still looking for a solution to this issue.... I just had the same problem, and fixed it, and I'll tell you how:
The .htaccess file in the subdomain has to, it would seem, take into account the full domain path... so, for you, you'd want to change the lines:
RewriteRule ^shirts/$ /shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1
into:
RewriteRule ^shirts/$ /shirts4mike/shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts4mike/shirts/shirt.php?id=$1
and really, you'd want to do that for everything in shirts4mike, if you'd like the 301 redirects to work!
Lonnie Wibberding
18,318 PointsIf it worked on a different server configuration my first suspect would be to look at any kind of $ROOT_SERVER variable or constant that may not be directing everything properly. Sorry, not much for further ideas.
Best wishes!