Welcome Guest, Not a member yet? Register   Sign In
Problem with URI segment length
#1

[eluser]afshin[/eluser]
Hi there.
I have been dealing with a code to retrieve some data from database using URI segment, but I faced a problem.


Of course, everything is okay until the the segment length is less than 56 characters.



This is what I have used in my model :


Code:
function view_news()
    {
        $newsId = $this->uri->segment(2);
        $newsStatus = 'published';
        $newsCategory = 'en';
        $query = $this->db->query("SELECT * FROM mavi_news WHERE newsId = '$newsId' AND newsStatus = '$newsStatus' AND newsCategory = '$newsCategory'");
        $query->num_rows();
        return $query->row();
    }


For example, if the link is:
http://example.com/news/10/this-is-what-...n-this-uri

it will retrieve data from database where the Id is 10, and the other segment is just for more information about the news and has nothing to do with the query

But, the problem is that when the modifier segment(3rd segment) is more than 56 characters, I get a browser(chrome) error which says :


Quote:Server error
The website encountered an error while retrieving
http://example.com/news/10/this-is-what-...n-this-uri
It may be down for maintenance or configured incorrectly.

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.



This is what I have in my routes.php file :


Code:
$route['news/(:any)'] = "main/news";


and this is my .htaccess file :

Quote:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>



I have no problem in localhost, and the problem is just in server.


I don't really know what the problem is ! Any suggestions?!
#2

[eluser]Jason Stanley[/eluser]
Do you have error reporting on? Are you logging errors?
#3

[eluser]afshin[/eluser]
The problem was with the default .htaccess file. I have changed it to

Quote:# Deny OR Allow Folder Indexes.
# Since we disable access to PHP files you
# can leave this on without worries.
# OR better yet, create a .htaccess file in
# the dir you want to allow browsing and
# set it to +Indexes
Options -Indexes

Options +FollowSymLinks

# Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>
# mod_rewrite rules
RewriteEngine on

# The RewriteBase of the system (if you are using this sytem in a sub-folder).
# RewriteBase /CodeIgniter_1.6.3/

# This will make the site only accessible without the "www."
# (which will keep the subdomain-sensive config file happy)
# If you want the site to be accessed WITH the "www."
# comment-out the following two lines.
# RewriteCond %{HTTP_HOST} ^www\.site\.com$ [NC]
# RewriteRule ^(.*)$ http://site.com/$1 [L,R=301]

# If a controler can't be found - then issue a 404 error from PHP
# Error messages (via the "error" plugin)
# ErrorDocument 403 /index.php/403/
# ErrorDocument 404 /index.php/404/
# ErrorDocument 500 /index.php/500/

# Deny any people (or bots) from the following sites: (to stop spam comments)
# RewriteCond %{HTTP_REFERER} nienschanz\.ru [NC,OR]
# RewriteCond %{HTTP_REFERER} something\.com
# RewriteRule .* - [F]
# Note: if you are having trouble from a certain URL just
# add it above to forbide all visitors from that site.

# You can also uncomment this if you know the IP:
# Deny from 192.168.1.1

# If the file is NOT the index.php file
RewriteCond %{REQUEST_FILENAME} !index.php
# Hide all PHP files so none can be accessed by HTTP
RewriteRule (.*)\.php$ index.php/$1

# If the file/dir is NOT real go to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

</IfModule>

# If Mod_ewrite is NOT installed go to index.php
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>


Now the problem of the length has been solved




Theme © iAndrew 2016 - Forum software by © MyBB