Welcome Guest, Not a member yet? Register   Sign In
.htaccess custom URL's
#1

[eluser]alphabase[/eluser]
Hi,

I am using CI with the Facebook SDK, and have decided to drop the index.php in my URL.
Now I'm trying to make custom URL's, for instance for the About-page.

Like this:
http://dev1.example.com/about rewrites to http://dev1.example.com/index.php/page/load/about

Here's my current .htaccess:
Code:
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

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

Could someone explain to me how to manage this?

EDIT:
Code:
$config['index_page'] = '';
$config['uri_protocol']    = 'AUTO';
$config['enable_query_strings'] = TRUE;
$route['default_controller'] = "topfive";
#2

[eluser]alphabase[/eluser]
Great, I solved it myself, sorry to bother the forum with this...

Here's my .htaccess:

Code:
<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase /

# Prevent access to the system directory
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

# Prevent access to the application directory
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

# Custom URL's
RewriteRule ^about/?$ controller/method/about [NC,L]

# Remove the index.php from the URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

Here's my config:
Code:
$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING';
$config['enable_query_strings'] = TRUE;

The problem was in the uri_protocol, which I changed from AUTO to QUERY_STRING.

Problem is resolved.
#3

[eluser]toopay[/eluser]
Actually you can still manage your application to remove the index.php from your uri. In some environment you need to set your uri_protocol to PATH_INFO, and in your htaccess remove '?' after index.php in the rewrite rule(you may net to tweak the regex rules too for that).
#4

[eluser]alphabase[/eluser]
I'm sorry to note that I don't understand what the (...) you're talking about, but I guess for others it might sound logical.
I've had some trouble with implementing the Facebook API (now using query_strings so that the SDK can grab the codes returned by Facebook via GET), and at the moment everything still works.

To conclude, my problem is resolved.
#5

[eluser]Mirge[/eluser]
[quote author="alphabase" date="1310012627"]I'm sorry to note that I don't understand what the (...) you're talking about,[/quote]

:lol: rofl
#6

[eluser]toopay[/eluser]
[quote author="alphabase" date="1310012627"]I've had some trouble with implementing the Facebook API (now using query_strings so that the SDK can grab the codes returned by Facebook via GET)[/quote]

I just actually let you know, why your previous code not works. I see you use '?' in your htaccess, and thats could tell php that no input being specified while you try to retrieve $_GET param. Because, in your previous htaccess, http://yoursite.com/somecontroller?code=foo is actually http://yoursite.com/index.php?somecontroller?code=foo.

But, if you already happy with your solution, that additional information still might usefull for your future reference.
#7

[eluser]alphabase[/eluser]
[quote author="toopay" date="1310015676"]I just actually let you know, why your previous code not works. I see you use '?' in your htaccess, and thats could tell php that no input being specified while you try to retrieve $_GET param. Because, in your previous htaccess, http://yoursite.com/somecontroller?code=foo is actually http://yoursite.com/index.php?somecontroller?code=foo.[/quote]

Allright, I'm listening, I guess it's starting to make sense to me now.
I understand that I should change my .htaccess to the following:

Code:
<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase /

# Prevent access to the system directory
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

# Prevent access to the application directory
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php/$1 [L]

# Footer custom URL's
RewriteRule ^about/?$ topfive/page/about [NC,L]
RewriteRule ^faq/?$ topfive/page/faq [NC,L]
RewriteRule ^contact/?$ topfive/page/contact [NC,L]
RewriteRule ^privacy/?$ topfive/page/privacy [NC,L]
RewriteRule ^termsofuse/?$ topfive/page/termsofuse [NC,L]

# Remove the index.php from the URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

And then I should change the following lines in my config.php:
Code:
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO';
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;

I've tested that, but when I do, the page always returns to the homepage, no matter what.

Got suggestions?
#8

[eluser]toopay[/eluser]
Whats happening if you ONLY put these htaccess
Code:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
and try access for example http://yoursite/welcome/?foo=bar, while at that welcome controller index function you dump the $_GET parameter. Is that works and outputing the right GET value? If not, you should make it works first, by tweak the regex on the RewriteRule (and as i stated, maybe you need try different uri protocol too, even generally AUTO setting should works in normal condition). For the htaccess rewriterule, you can try these combination (this is from my working htaccess in several "weird" environment, like cenTOS with cherooke and other linux distro)
Code:
# try these combination to replace last line in above htaccess
RewriteRule ^.*$ index.php/$1 [L,QSA]
# or these one
# RewriteRule (.*) index.php/$1 [L,QSA]
Dont forget to clear your browser history and browser cache FIRST, before try on each htaccess configuration, otherwise it might be your browser just took the result from its own cache or history!




Theme © iAndrew 2016 - Forum software by © MyBB