I'm developing a website using Kohana 3 (1rst time I use a framework). Locally, everything works perfectly. At the moment, I have a default template controller, a multi-language support and my 'index.php' is correctly removed. So before going further, I tested if it worked on my server and I got an endless loop.
I followed the tutorial from the unofficial wiki for the multi-language implementation: http://www.kerkness.ca/wiki/doku.php?id=example_of_a_multi-language_website
A redirection to the default language occurs if the language is not specified in the uri so I figured the problem might have come from there even though it worked locally, so I removed it to see what happens without the redirection. Now, I can see my home page, but whatever the uri is in the web browser, the home page will always be called. I inserted the following line in my home view to check what the uri was:
request::instance()->uri() and effectively, the uri is always: /en/home/
I put the index.php back (in the bootstrap) and everything worked fine again, even with the redirection to the default language.
My first guess was that the uri isn't rewritten correctly, so I tried to change the .htaccess but no success...
Here's my .htaccess:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /dev/
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system)/ - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
(btw I also tried the other RewriteRule in the unofficial wiki, doesn't work either)
Additional info:
Host: WebHostingPad
Apache: v2.2.11
PHP: 5.2.9
Rewrite_Module is activated
Thank you, I would really appreciate your help because I've been trying to fix this for days now and it's really starting to annoy me ;)
The only thing you have to change in order to get rid of index.php in URL is to set the 'index_file' param in Kohana::init ( bootstrap.php ) to FALSE ( everything else can cause an error ).
So the Kohana::init looks like this;
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
));
If it worked with the original .htaccess, there's no need to change it at all.
The problem came from $_SERVER['PATH_INFO'] which returned no value...
This issue can be solved by adding the following line to the php.ini:
cgi.fix_pathinfo=0
Related
I'm going crazy here! I'm trying to learn Laravel and pretty URLs just don't work.
I have enabled mod_rewrite from my apache config file, I have set AllowOverride to All in my user config file and I have the following in my .htaccess file in public folder of Laravel installation:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
I enter http://localhost/~user/lara/public/index.php/users it works, but with http://localhost/~user/lara/public/users I get 404 Not Found error
The requested URL /Users/user/Sites/lara/public/index.php/users was not found on this server.
You can see that the redirection works fine, as public/users have turned into public/index.php/users but it says not found, even though when I manually enter public/index.php/users it show me the output.
I have read all the related questions on SO, none of the worked for me!
This is most likely caused by the fact that you are changing the document root during a request. From the looks of your URL (with the ~user segment) you are using mod_userdir or something similar, and what these types of plugins do it allow you to map a given URL prefix to a document root that is not the normal one for the server.
As such, you sometimes run into issues like this where the right .htaccess file is found, but its rewritten URL is against the original document root rather than the modified one and so your index.php file cannot be found (maybe, to be honest I don't really know, this is all conjecture). This is also why going directly to index.php/users works - the problem isn't the setup per se, but the mixing of rewrite rules and the change of the document root.
As such, the fix is to use a RewriteBase line, ad the following to the .htccess file:
RewriteBase /~user/lara/public/
alright so i have a need for mode rewrite and i am completely noob/new to it.
I've read sever guide. that explained mode rewrite goes - pattern - redirection - flags.
i am trying to redirect anyone that gets into domain.com/product/ to domain.com/product.php
and pass the variable url=232 however i am first trying to redirect /product/ to product.php
Here is what i got so far.
Options +FollowSymLinks
RewriteEngine On
RewriteRule \/product\/ /product.php
I've started even more basic then that by redirect product.php to index.php and that worked.
am i doing something wrong ?
RewriteEngine On
RewriteBase /
RewriteRule ^product/?$ /product.php?url=232
I have this in my htaccess, standard domain redirection:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ "http\:\/\/fullnewdomain\.org\/$1" [QSA,R=301,L]
And it works fine for folders, subfolders, html files, images, etc. However, for some reason it refuses to redirect php files. Instead they still run as normal and do not redirect to the new domain. Any ideas as to why, and how I can fix it? It's almost like this host is trying to execute the php file before checking any rules ( And I'm not sure what I could do if that's the case! ).
Turns out there was an htaccess file the host had placed in the home directory ( One level above public_html ) to "counter" bots, but all it did was break anything else that tried to apply a rule to php files. Removed the file, problem solved itself.
For reference, hostgator was the host, and I still don't know why they felt the need to place the file there in the first place.
I'm trying to redirect all pages on an old site (wellnowwhat.net/nin/*.*) to the index of a new site (sykonaut.net/nin_old/). I only have access to the new site's .htaccess (the old site is owned by a friend), so I'm testing going the opposite direction. I can redirect the root (sykonaut.net) to his root (wellnowwhat.net) using mod_rewrite, but I cannot redirect my nin_old directory to his nin directory. I'm guessing I wouldn't be able to redirect the opposite direction, either. Here is [the entirety of] the code in my .htaccess:
AddHandler php5_2-wrap .php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.sykonaut.net$ [NC]
RewriteRule ^/nin_old(.*)$ http://www.wellnowwhat.net/nin [R,NC,L]
It does not work. Anyone know why?
Place your .htaccess in the nin_old directory.
RewriteEngine on
RewriteBase /nin_old
RewriteRule ^.* http://www.wellnowwhat.net/nin/ [R,NC,L]
When you redirect to an external URL to a directory, I would add the trailing slash as this reduce an extra redirection.
Also when you test everything and it's all right, change R to R=301 as this is preferred by most search engine for Permanent Redirection.
In apache 2.0 and higher, the prefix (leading "/") is removed from the URI before it's put through the rewrite engine for rules in the .htaccess file. Try removing the leading slash from your regular expression in your rule:
RewriteRule ^nin_old(.*)$ http://www.wellnowwhat.net/nin [R,NC,L]
I'm trying use mod_rewrite to rewrite URLs from the following:
http://www.site.com/one-two-file.php
to
http://www.site.com/one/two/file.php
The folders don't exist, but "virtually" exist for the rewriting purpose.
What rule do I used in this?
Untested:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)\.php$ $1-$2-$3.php [L]
I can't really understand your explanations about virtuality and existence: one-two-file.php must exist or you'll have nowhere to redirect to.
Update
The previous version works fine when used from an .htaccess file. However, if used from main http.conf file you need to add leading slashes:
RewriteRule ^/([^/]+)/([^/]+)/([^/]+)\.php$ /$1-$2-$3.php [L]
I presume that's why it wasn't working for the OP (he was probably getting a 404 not found status code).