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

Development Tools

Joan Valls de Padrines Amengual
Joan Valls de Padrines Amengual
11,760 Points

RewriteRules again (XAMPP)

After I had some big problems with the RewriteRules working on a subfolder in local and production server (solved by creating subdomains both local and production), now I have weird ones with just one rewrite type.

This is only happening in the localhost, on the production server (shared hosting) works fine.

I'm working with XAMPP on Windows.

My htaccess looks like this:

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 have the subdomain tenda.localhost created on my httpd-vhosts.conf created and working.

When I type or follow a link to any of the /shirts/XXX/ URL it goes to http://tenda.localhost/%20shirts/.

No idea where the whitespace is (%20). All other RewriteRules workes perfect, just the ones that use shirt.php.

I activated the rewrite logs (no idea where to look but did it). I didn't nothing weird until a block of the logs where it says something like this and looks is when the whitespace is included in the URL:

[Thu Sep 11 21:20:11.982260 2014] [rewrite:trace3] [pid 5588:tid 1636] mod_rewrite.c(475): [client 127.0.0.1:55508] 127.0.0.1 - - [tenda.localhost/sid#746540][rid#313fce0/initial] [perdir C:/xampp/htdocs/th-php/] strip per-dir prefix: C:/xampp/htdocs/th-php/ shirts/ ->  shirts/
[Thu Sep 11 21:20:11.982260 2014] [rewrite:trace3] [pid 5588:tid 1636] mod_rewrite.c(475): [client 127.0.0.1:55508] 127.0.0.1 - - [tenda.localhost/sid#746540][rid#313fce0/initial] [perdir C:/xampp/htdocs/th-php/] applying pattern '^shirts/$' to uri ' shirts/'
[Thu Sep 11 21:20:11.982260 2014] [rewrite:trace3] [pid 5588:tid 1636] mod_rewrite.c(475): [client 127.0.0.1:55508] 127.0.0.1 - - [tenda.localhost/sid#746540][rid#313fce0/initial] [perdir C:/xampp/htdocs/th-php/] add path info postfix: C:/xampp/htdocs/th-php/ shirts -> C:/xampp/htdocs/th-php/ shirts/

This is getting me crazy... Can anyone help me?

Thx

2 Answers

I had a similar issue, always landing on the shits page...

For me it was some tiny typo in one of the include lines, and in the one of the links in the shirts page. Make sure all your includes and links use and echo the right paths.

Unfortunately I don't remember which link it was exactly, but i would recommend to check them all or use the file from the instructor to compare it with yours.

Joan Valls de Padrines Amengual
Joan Valls de Padrines Amengual
11,760 Points

Indeed it was. I found the problem in the function where the single shirt is loaded. All working fine now either in localhost and shared hosting.