Welcome Guest, Not a member yet? Register   Sign In
Problem rewriting links in htaccess
#1

Hey, I have "index.php?" in my links, I have searched for a solution all over the forum
and I could'nt find something that works for me.

"http://mywebsite.com/index.php?video/xxxxxx"
I am trying to change it to "http://mywebsite.com/video/xxxxxx"

now, I have tried to it in htaccess with no success.

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

What I am doing wrong? HELP Exclamation  Exclamation
Reply
#2

Hey chiefdongas,

Check your config.php in the config folder. Look for the following line and check that index_page is not set to the default value, index.php: 
Code:
$config['index_page'] = '';

It should be set to an empty string when you use rewrite.

Good luck!

-Rogier
Reply
#3

(02-05-2015, 07:57 AM)chiefdongas Wrote: Hey, I have "index.php?" in my links, I have searched for a solution all over the forum
and I could'nt find something that works for me.

"http://mywebsite.com/index.php?video/xxxxxx"
I am trying to change it to "http://mywebsite.com/video/xxxxxx"

now, I have tried to it in htaccess with no success.

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

What I am doing wrong? HELP Exclamation  Exclamation

First thing is if you are using the link helper --> anchor() function and are still getting an index.php in your links, that means you have to go to your config file and update your index page --> Go to your application/config/config.php file ->Go to about line 30 and change:

PHP Code:
$config['index_page'] = 'index.php';

// to:

$config['index_page'] = ''

Also i'm not great with .htaccess rules but here is mine that works:

Code:
<IfModule mod_rewrite.c>
    
    Options +FollowSymLinks
    RewriteEngine on
    
    # Send request via index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php?/$1 [PT,L]

</IfModule>
Reply
#4

Thank you for the fast respond
I have changed the config and the htaccess
and now the link http://mywebste.com/?video/xxxxxx works
but when I try "http://mywebste.com/video/xxxxxx" it goes to 404.
I'm stuck with that question mark
any toughts?
Reply
#5

Lose the ? in the following line:
Code:
RewriteRule ^(.*)$ /index.php?/$1 [L]

What you get is obviously:
Code:
RewriteRule ^(.*)$ index.php/$1 [L]

Good luck!

-RogerMore
Reply
#6

(02-06-2015, 01:28 AM)RogerMore Wrote: Lose the ? in the following line:

Code:
RewriteRule ^(.*)$ /index.php?/$1 [L]

What you get is obviously:

Code:
RewriteRule ^(.*)$ index.php/$1 [L]

Good luck!

-RogerMore

Hi,
The question mark still stays. maybe it's something in my code?
Reply
#7

(02-06-2015, 02:03 AM)chiefdongas Wrote:
(02-06-2015, 01:28 AM)RogerMore Wrote: Lose the ? in the following line:


Code:
RewriteRule ^(.*)$ /index.php?/$1 [L]

What you get is obviously:


Code:
RewriteRule ^(.*)$ index.php/$1 [L]

Good luck!

-RogerMore

Hi,
The question mark still stays. maybe it's something in my code?

Hi, check config item...
$config['enable_query_strings'] it must be FALSE!
Reply
#8

Here are my .htaccess that works great in my local pc and in production using a vps


For local use with http://localhost/ or production with a domain like http://example.com/


Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]

For user directory (mod_userdir enabled) something like: http://example.com/~userdir/project/


Code:
RewriteEngine on
RewriteBase /~userdir/project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

In both cases I use:


PHP Code:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['encryption_key'] = 'myencryption_key';
//all remaining is the default config 

Hope this helps
Reply




Theme © iAndrew 2016 - Forum software by © MyBB