Kohana in subdirectory - .htaccess

I need to put Kohana 3 project to subdirectory.
Now when I type mysite.xyz/<subdirectory> it run properly (default controller load ok).
But, when I type:
mysite.xyz/<subdirectory>/<controller>
or
mysite.xyz/subdirectory>/<controller>/<method>
that redirect me to
mysite.xyz/<controller>/<method> and fails (Not found requested url).
<subdirectory> = /folder1/folder2/folder3/
I had changed base url in kohana.
Here is my .htaccess:
RewriteEngine On
RewriteBase /folder1/folder2/folder3/
###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*)folder1/folder2/folder3/index.php/(.*)$ /$1$2 [R=301,L,NE]
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media)
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L,QSA]
Please help.

Related

remove inside url some element via htaccess

Via an htaccess, I want to remove this point inside url : Products/Description
example : https://test.com/Products/Description/logitech/Id-12
I tried this but it does not work.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ Products/Description/$1$2 [L]
below is my complete htaccess tried rules file:
RewriteEngine On
DirectorySlash Off
# Remove WWW
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=302,L]
# Remove Trailing Slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)//+[?\s]
RewriteRule ^ %1 [R=302,L]
# Reroute to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
# Remove Products/Description ===> not working
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ Products/Description/$1$2 [L]
With your shown samples and efforts, please try following .htaccess rules file. We need to do few changes in it. Make sure that your .htaccess file is residing along with Products folder(not inside it, besides it).
Also make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /Products/Description/
DirectorySlash Off
# Remove WWW
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=302,L,NE]
# Remove Trailing Slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)//+[?\s]
RewriteRule ^ %1 [R=302,L]
RewriteCond %{THE_REQUEST} \s/index\.php\?([^&]*)&([^&]*)&Id=(\d+)\s [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(Products)/(Description)/(\d+)/?$ index.php?$1&$2&Id=$3 [QSA,NC,L]
# Reroute to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Redirect / remove links by question mark

I need to remove all links that have a question mark. These are links not indexed by Google.
I can't find a solution to this problem.
Example:
http://example-page.pl/pl?start=18 --> http://example-page.pl/pl
HTACCESS:
...
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
...
Use a RewriteCond to check if there is a query string, then using RewriteRule redirect only the first part of the url.
Input: http://example-page.pl/pl?start=18
RewriteCond %{QUERY_STRING} .
RewriteRule ^(.*)$ /$1? [R,L]
Output: http://example-page.pl/pl
You can view this working via htaccess.madewithlove.be.

Double slash in url after domain name [Kohana]

I have a problem with URLs in Kohana framework.
When I type mydomain.xyz/admin that redirect to mydomain.xyz//admin and return some errors from Kohana core.
Here is a part of my .htacces:
RewriteEngine On
RewriteBase /
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media)
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L]
###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ $1/ [R=301,L]
RewriteRule ^(.*)public_html/index.php/(.*)$ http://mysite.xyz/$1$2 [R=301,L]
That problem has appeared after move site from other server.
Have it this way:
DirectorySlash Off
RewriteEngine On
RewriteBase /
###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*)public_html/index.php/(.*)$ /$1$2 [R=301,L,NE]
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media)
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L,QSA]
Make sure to clear your browser cache before testing this change.

Enforcing trailing slash, and removing index.php with htaccess placed in subfolder

I have a CodeIgniter project placed in a subfolder of a domain.
I want to have my .htaccess (placed in the CodeIgniter subfolder) to do the following, for any url involving the CodeIgniter directory:
Remove "index.php" from any url.
Always add a trailing slash to any url.
Currently my .htaccess look like this:
RewriteEngine on
RewriteBase /ci_folder/ #This is the CI Subfolder
# Get rid of index.php
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
# Add trailing slash
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*[^/])$ $1/ [L,R=301]
The problem is, that its only working partially; The index.php is removed fine, but when adding the trailing slash, instead of redirecting to a "fixed" url, its redirecting to the local path, fx.
domain.com/ci_folder/method
is redirected to:
domain.com/home/sites/domain.com/public_html/ci_folder/index.php/method/
which should have been : domain.com/ci_folder/method/ instead! (and also not include any index.php)
--- EDIT ---
This did it for me:
RewriteEngine on
RewriteBase /ci_folder/
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]
RewriteCond %{REQUEST_URI} !(.*)/$
# dont rewrite if there was posted here!
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*[^/])$ $1/ [L,R=301]
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
RewriteEngine on
RewriteBase /ci_folder/
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]
RewriteCond %{REQUEST_URI} !(.*)/$
# dont rewrite if there was posted here!
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*[^/])$ $1/ [L,R=301]
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

.htaccess how can I implement both "vanity url" and "no extension"

I'm using htaccess from stackoverflow.com/q/8583856 -
RewriteEngine on
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.mysite.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.mysite.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://www.mysite.com/profile.php?u=$1 [NC]
Everything works great unless I type www.mysite.com into address bar -
returns mysite.com/profile?u=index.html.var
which errors "Unknown column index.html.var in where clause"
Anyone know how to get this to go to mysite.com/index instead?
Change your code to this and let me know how it behaves (after clearing your browser cache):
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [R=302,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ $1 [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ profile.php?u=$1 [NC,L]
Once you're sure it is working then change R=302 to R=301
try adding a condition to check if the path is empty (i.e. root)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond $0 ^$
RewriteRule .* - [L]

Resources