Welcome Guest, Not a member yet? Register   Sign In
.htaccess problem
#1

[eluser]Gaetan81[/eluser]
hello,

I recently started to use codeigniter. I must say its a great framework!

Still I have some problems with my .htaccess

Code:
RewriteEngine On

# Add www
    RewriteCond %{HTTP_HOST} ^myurl\.com$ [NC]    
    RewriteRule ^(.*)$ http://www.myurl.com/$1 [L,R=301]

# Add Trailing Slash  
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://www.myurl.com/$1/$2 [R=301,L]

    RewriteRule ^(/?)$ /index.php
    RewriteRule ^([a-z]+)(/?)$ index.php/$1

when I go to myurl.com/users/ everything just works fine. But when I add for example myurl.com/users/edit/25 he doesnt find the page.

Whats wrong to my .htaccess?

Tia
#2

[eluser]GSV Sleeper Service[/eluser]
the [L] is most probably your problem.

from the rewrite docs

'last|L' (last rule)
Stop the rewriting process here and don't apply any more rewrite rules. This corresponds to the Perl last command or the break command in C. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. For example, use it to rewrite the root-path URL ('/') to a real one, e.g., '/e/www/'.
#3

[eluser]Gaetan81[/eluser]
thx you for the fast reply.
But it still doesn't work.

myurl.com/users/ -> works
myurl.com/users/edit/25/ -> doesn't work.

when I disable the .htaccess en put index.php in the config file, everything works just fine.

myurl.com/index.php/users/ -> works
myurl.com/index.php/users/edit/25/ -> works

Tia!
#4

[eluser]Pascal Kriete[/eluser]
I'm pretty sure it's this line:
Code:
RewriteRule ^([a-z]+)(/?)$ index.php/$1

That will match any character from a to z as many times as possible and then an optional / . The problem with users/edit/25 is that the slashes and numbers don't match.

Does this work?
Code:
RewriteRule ^([\w/]+)(/?)$ index.php/$1
#5

[eluser]Gaetan81[/eluser]
thx for the fast reply.

But still no luck.

I'm now trying this

Code:
# Add www
    RewriteCond %{HTTP_HOST} ^myurl\.com$ [NC]    
    RewriteRule ^(.*)$ http://www.myurl.com/$1 [L,R=301]

# Add Trailing Slash  
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://www.myurl.com/$1/$2 [R=301]

# When lang is defined but trailing slash AND page isn't:
    RewriteRule ^([a-z]+)$ index.php [L,NC]
# When lang and trailing slash is defined BUT page isn't:
    RewriteRule ^([a-z]+)/()$ index.php/$1 [L,NC]

Tia
#6

[eluser]Pascal Kriete[/eluser]
Your second block forces the trailing slash, but then you're checking for it at the bottom. I think you're making this more complicated than it has to be.
#7

[eluser]Gaetan81[/eluser]
Ok, new start.

Now, I have this.

Code:
RewriteEngine On
RewriteRule ^(/?)$ /index.php
RewriteRule ^([\w/]+)(/?)$ index.php/$1

myurl.com/users -> doesn't work
myurl.com/index.php/users -> work

Tia!
#8

[eluser]codex[/eluser]
[quote author="Beertje81" date="1213635634"]Ok, new start.

Now, I have this.

Code:
RewriteEngine On
RewriteRule ^(/?)$ /index.php
RewriteRule ^([\w/]+)(/?)$ index.php/$1

myurl.com/users -> doesn't work
myurl.com/index.php/users -> work

Tia![/quote]

But what is it you're trying to achieve? Remove index.php from the url? If so, this is my .htaccess (which works):
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA]


Btw, are you Dutch?
#9

[eluser]Gaetan81[/eluser]
Hello,

Dutchspeaking yes, I'm from Ghent,Belgium.

Sorry no luck, again.
Yes I want to remove the index.php from the url.

Tia
#10

[eluser]codex[/eluser]
[quote author="Beertje81" date="1213663598"]Hello,

Dutchspeaking yes, I'm from Ghent,Belgium.

Sorry no luck, again.
Yes I want to remove the index.php from the url.

Tia[/quote]

Dat moet ook haast wel met een naam als Beertje ;-)

Have you defined the route in routes.php?




Theme © iAndrew 2016 - Forum software by © MyBB