How do I set default page for my website if the index file is located inside a couple of more folders in htdocs? - mod-rewrite

When I load my website I want the default page to be loaded but it is located inside two more folders in htdocs. I tried changing .htaccess but it did not work as I expected. This is my directory structure:
htdocs\hotel-management-repo\hotel-app\index.php

What rule did you apply in the .htaccess? Have you tried something like:
RewriteRule ^index.php$ hotel-management-repo\hotel-app\index.php [QSA,L]

Related

Laravel 8 project deploy to shared hosting - security issues and public_html folder

I was able to deploy my laravel 8 application as and addon domain on inmotion shared hosting based on the following article
https://medium.com/backenders-club/how-to-host-a-laravel-project-on-a-shared-hosting-via-cpanel-d955d32c528e
However, there are security issues with this as I can type mysite.com/.env and the file contents is listed in the browser showing the passwords.
I've tried many options to place the public folder of my laravel app into a public_html/public folder and none have worked for me. Anyone also getting this problem?
Addon domain Document root - /public_html/public
Laravel 8 application - /mysite.com (public folder contents moved to public_html/public)
Inside the public_html/public folder, the index.php file modified as follows:
require __DIR__.'/../../mysite.com/vendor/autoload.php';
$app = require_once __DIR__.'/../../mysite.com/bootstrap/app.php';
In browser I get 'No input file specified.'
bad practice if you try to move files inside public folder to root directory , any one can view the files that exist in the root ,
my advice to you ,return your files to the public folder and use one solution from this :-
first , you can make change the domain document root to public path
second you can create .htaccess file in the root folder and contain this code :-
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
i prefer the first solution.

How to setup laravel in this url format http://ip-address/~username

I had setup Laravel projects before but this is my first time setting it up on this url format: http://ip-address/~username.
When I first visited the url, it just shows the directory listing so I tried accessing it by appending /public in the url and it works. However all the other links have /public on it and leads to a 404 error.
This is the current directory structure:
inside public_html
- app
- bootstrap
- config
- database
- public
- other folders
- htaccess
- other files
I tried putting an htaccess file in the project root folder.
<IfModule mod_rewrite.c>
Options -Indexes
RewriteEngine On
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
However it still doesn't work and I don't know what to do anymore. If you have been in this kind of situation before, please help me. Thank you in advance.
You'll need to set your WebServer's document root to the public directory, that way it looks in the public and you wont have to append your url with public all the time.
Either that or you'll have to move your index.php out of the public directory and put it inside the root directory your web server is currently set as, but I would recommend you do the first option.

Transferring codeigniter HMVC project from localhost to live server

I made a web application on codeigniter HMVC. I tested it on local server and the following link works perfectly fine by giving me a login form, the link : http://localhost/bird_vision/users/login, where my directory structure goes like this bird_vision/application/modules/users/users.php (users->module's name, users.php->controller's name). Now I posted the whole "bird_vision" folder to web using filezilla.
- changed the base_url in config.php file to domain_name
- Made some changes in .htaccess file
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$10 [L,QSA]
</IfModule>
Now when I write bird_vision.se/bird_vision/users/login in my address bar it gives me 404 page not found. Although when I when type birdvision.se/bird_vision/welcome it gives me welcome to codeigniter page.
Please I need help as my all hardwork making this project is at stake. Thanks in advance.
I figured the problem was not with HMVC but was with codeigniter version 3.0. When it comes to unix(which was the operating system running on my server), it is case sensitive. So when I tried to access the controller it could'nt find the file because of case sensitivity and a 404 popped out everytime.
My folder structure before was something like :
-application
-->modules
--->users
---->controllers
----->users.php
And the link on which I was getting 404 was www.example.com/users/login
where "users" in the link is controller's name within the "controllers" folder under "modules" folder in my case named as users.php and "login" is the function inside the controller.
All I had to do was to change the case of the first letter of my module and controller name. Now my directory looks like
-application
-->modules
--->Users
---->controllers
----->Users.php
note : capitalized "U" in Users module and Users controller.
And the the url I used to access the users controller was : www.example.com/Users/login
And I was back in business.

issue with shifting Kohana 2.4 from root location to make it accessible via a directory?

I have developed a kohana project 2.4 version, with i has been developed by configuring virtual host and we are accessing it using some domain aa.com, now i have to move the project to folder named kohana and make it access via aa.com/kohana. If i access it this way then my url changes, So the css & js file are not included since the src url i have provided like /public/css/ so it's not working, same goes for calling a controller. like il be calling a controller using this format /user/login/. now the url when i click to shows like aa.com/user/login which is not found, in turn it should automatically comes like aa.com/kohana/user/login. Is there any way by changing the htaccess file or hacking routes.php file. ?
I should able to automatically append /kohana/ before the url.
Please suggest me a method how it can be achieved.
Yes there is!
I've only started after kohana 3.0 but you can just change the rewritebase.
In your .htacces it probably says "rewritebase /"
Change this to your new directory. "rewritebase /kohana/"
If 2.4 has a bootstrap (i'm not sure) somewhere it should say "base_url". You change this the same as the .htaccess. /kohana/.
edit: here's an example:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /kohana/
# 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,L]

Reaching files outside od the documentroot scope

I'm writing a script to build a dynamic website,
the website is created by loading external components.
The DocumentRoot is location at /sites/website/public
the components directory is located at /sites/website/components
i wannna reach the data directory of each component depends on the requested url.
for example:
the url:
http://ibuildmywebsite/component-data/randomimage/demo/swan04090044_small.jpg
should fetch the file /sites/website/components/randomimage/data/demo/swan04090044_small.jpg
how can i achieve that ?
i would prefer a way that can be placed inside .htaccess (if there is one) instead of modifying the virtual host definitions.
Thanks!
Combine RewriteRule with Alias maybe ?
Alias /randomimage /sites/website/components/randomimage
RewriteRule ^component-(.*)/randomimage/(.*)$ /randomimage/$1/$2 [R,L]
(Won't work in .htaccess though)
You could probably also use Symlinks with:
Options +FollowSymLinks
And link dynamically components-*/randommimage/* to /sites/website/components/randomimage/*/*/

Resources