Jump to content

htacces issue


DaveyK
Go to solution Solved by requinix,

Recommended Posts

Hey Freakers,

 

I have an issue in my htaccess again... To better explain, I have attached two screenshot. The first is how it is SUPPOSED to look like (localhost) and the second is from the server. As I said, the first is how it supposed to look like. It is a screen of the blogpost. The second, however, displays the screen from the blog "homepage" (so the page that shows all the blog posts rather than that single one.)

 

You may see it for yourself at http://trekeffect.com/developers-blog, then click the blog title link and the page will refresh, but nothig will change. I started tracing the problem and it appears to be in the htaccess, but the htaccess on the server and localhost are identical. The way I found out is to var_dump $_GET in php. Localhost will show an array with the id and title, while the server array is (shockingly) empty. Here is the htaccess I am using on the server:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
</IfModule>

RewriteCond %{HTTP_HOST} ^www.trekeffect.com$ [NC]
RewriteRule ^(.*)$ http://trekeffect.com/$1 [R=301,L,S=4]

# If requested resource exists as a file or directory, skip next three rules
RewriteCond %{DOCUMENT_ROOT}/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule (.*) - [S=3]

# Blog articles. TEST TEST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?developers-blog/([^/]+)/(\d+)/(\d+)$ developers-blog.php?title=$1&id=$2&reply_to=$3 [L,S=1]
RewriteRule ^/?developers-blog/([^/]+)/(\d+)$ developers-blog.php?title=$1&id=$2 [L]

# Remove the .php extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteRule (.*)\.xml(.*) $1.php$2 [nocase] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app.php?tag=$1 [QSA,L]

# ----------------------------------------------------------------------
# Custom 404 page
# ----------------------------------------------------------------------
 
# You can add custom pages to handle 500 or 403 pretty easily, if you like.
ErrorDocument 403 /error.php?type=403
ErrorDocument 404 /error.php?type=404
ErrorDocument 500 /error.php?type=500

The fact that files who are (supposedly) exactly the same would give different results is puzzling me. Any idea what is going on?

 

Thanks!

post-139396-0-82739600-1366361512_thumb.png

post-139396-0-16183200-1366361522_thumb.png

Link to comment
Share on other sites

  • Solution

Try with

Options +FollowSymlinks -MultiViews
Also worth noting,

# Blog articles. TEST TEST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?developers-blog/([^/]+)/(\d+)/(\d+)$ developers-blog.php?title=$1&id=$2&reply_to=$3 [L,S=1]
RewriteRule ^/?developers-blog/([^/]+)/(\d+)$ developers-blog.php?title=$1&id=$2 [L]
That won't behave they way I think you think it will behave. RewriteConds only apply to the next RewriteRule so what you have there is not equivalent to

# Blog articles. TEST TEST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?developers-blog/([^/]+)/(\d+)/(\d+)$ developers-blog.php?title=$1&id=$2&reply_to=$3 [L,S=1]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?developers-blog/([^/]+)/(\d+)$ developers-blog.php?title=$1&id=$2 [L]
Link to comment
Share on other sites

Ah, great, then now I can explain what happened.

 

The MultiViews option allows you to omit file extensions (from file types known to Apache) in your URLs. Like "/developers-blog" will automatically map to developers-blog.php. Thing is that Apache doesn't require a directory structure, so "/developers-blog/123" will map to "/developers-blog.php/123" (which is a very valid CGI path). Problem is (1) you have RewriteConds that (rightfully) demand that the requested file not exist, which in this case it does, which could be okay but (2) developers-blog.php can't interpret CGI paths and needs traditional query string variables. Presumably.

 

-MultiViews to turn that feature off, "/developers-blog/123" tries to map to a file 123.* in the developers-blog directory, Apache can't find it, and your URL rewriting rules kick in as you want them to.

Link to comment
Share on other sites

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.