Jump to content

Third RewriteRule creating 404 error


Recommended Posts

AuthType Basic
AuthName "Development Area"
AuthUserFile /path/to/.htpasswd
Require valid-user

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain.tld [NC]
RewriteRule ^(.*) http://domain.tld/$1 [L,R=301]

RewriteRule ^state/([a-z]{2}) /index.php?state=$1 [NC]

RewriteRule ^variable/([0-9]{1,3}) /variable.php?id=$1 [NC]
</IfModule>

 

My third RewriteRule is causing my page to kick out a 404 error. Does anyone know why this might be happening? The URLs are formatted correctly in the address bar (example: domain.tld/variable/23).

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/202843-third-rewriterule-creating-404-error/
Share on other sites

Hmm. I do in fact have a variable.php file in my root directory.

 

I know this for few reasons:

1. I am looking at it via my FTP client.

2. When I hit that page with no passed variables, the page loads with the custom error message programmed on the page saying that it can't find any valid parameters.

3. When I get rid of the RewriteRule and use "the old way," it works fine.

 

The "old way" is ugly to me. I guess I can keep using it until we figure this out. I wish I knew more about .htaccess, so I don't really know any suggestions to make. I'm kind of at a loss.

Are you sure you are typing in both the rule and the URL correctly? If it's not being rewritten in the address bar then it is not being rewritten at all which means it is not matching that RewriteRule. The only other thing I can think of is it's because you have L in your rewriterule for removing www at the start. Are you attempting to test it by using http://www.domain.tld/variable/23? Try removing the other rules see if it works on it's own, and check spelling.

I commented out the first rules and still nothing happens with the Rewrite. I double and triple checked the spelling as well. Here's the latest copy:

AuthType Basic
AuthName "Development Area"
AuthUserFile /path/to/.htpasswd
Require valid-user

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
#RewriteCond %{HTTP_HOST} ^www\.domain.tld [NC]
#RewriteRule ^(.*) http://domain.tld/$1 [L,R=301]

RewriteRule ^state/([a-z]{2}) /index.php?state=$1 [NC]

RewriteRule ^variable/([0-9]{1,3}) /variable.php?id=$1 [NC,R=302]
</IfModule>

 

It's not a huge deal to have the "pretty" URLs. I can deal with it for now.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.