Jump to content

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.

Changing it to...

 

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

 

...will show you in the address bar the URL that it is actually trying to access, this should hopefully point out why it's not being found.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.