I made a directory in my host:
www.mysite.com/test/
and I've copied my laravel folders inside it. but when I call that url on my browser it show me this:
I think I should make a .htaccess .
Here is sample for my case and your case:-
My Case:-
URL Before .htaccess www.xyz.com/public/index.php
URL After .htaccess www.xyz.com
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* public/index.php [L]
Your Case:-
URL Before .htaccess www.xyz.com/test/public/index.php
URL After .htaccess www.xyz.com
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* test/public/index.php [L]
The Laravel app is inside /public folder, which also already has a .htaccess: mysite.com/public/test
What you can do is symlink the project/public folder to the public directory. For example:
ln -s /path/to/project/public /var/www
Now you should be able to see the app on mysite.com/test.
This article on deploying a Laravel 5 application might help.
The
.htaccess
file is already existed in public folder what you need to configure is your server
for Linux on terminal execute :
cd /etc/apache2/sites-available
/etc/apache2/sites-available$ sudo vi myapp.conf
Add/Modify these lines to suit your server
<VirtualHost *:80>
ServerName myapp.localhost.com
DocumentRoot "/home/vagrant/projects/myapp/public"
<Directory "/home/vagrant/projects/myapp/public">
AllowOverride all
</Directory>
</VirtualHost>
Save the file, then continue below.
/etc/apache2/sites-available$ cd ../sites-enabled
/etc/apache2/sites-enabled$ sudo ln -s ../sites-available/myapp.conf
/etc/apache2/sites-enabled$ sudo service apache2 restart
And for Windows Servers inside your Laravel root folder add web.config file and write these codes inside it
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="default.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
</files>
</defaultDocument>
<handlers accessPolicy="Read, Execute, Script" />
<rewrite>
<rules>
<rule name="Imported Rule 1">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="/public/{R:1}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="public/index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
)
Create an .htaccess file on your laravel's root directory. This is to access it without the "public" on the url
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI}!^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Related
I would like to take the following URL
http://MYSERVER/API_Tasks/V1/controller/task.php?taskid=2
and rewrite it to:
http://MYSERVER/API_Tasks/V1/tasks/2
I have the following rule created but it does not seem to work
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^tasks/([0-9]+)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="controller/task.php?taskid={R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
original Apache .htaccess rules
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^tasks/([0-9]+)$ controller/task.php?taskid=$1 [L]
The issue was actually caused by the rule in IIS being placed on the API_Tasks directory and not the API_Tasks/V1 directory. Adding the URL rule to the V1 fixed the issue.
I have main domain and I want to rewrite images form another one to main without redirect
Here is my code:
RewriteCond %{HTTP_HOST} ^www.mydomain\.eu$ [NC]
RewriteRule ^images/(.*)$ https://www.mydomain.cz/images/$1 [NC]
It always does 302 redirect.
Is there any way how to do this? I am using ISAPI_Rewrite, but I tried IIS 10 rewrite too, but I am not familiar with that and I wasnt successful at all
Thanks
According to your description, I suggest you could try to below use url rewrite rule in the IIS.
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^images/(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www.mydomain\.eu$" />
</conditions>
<action type="Rewrite" url="https://www.mydomain.cz/images/{R:1}" />
</rule>
Here is what i got, i tried putting .htaccess on root with following code :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
And on public folder .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
This is error i'm having on localhost :
And this is the error i'm having on shared hosting server :
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "^5.4.0"
}
No success yet. Please help i couldn't sleep
Alright i resolved my own problem
I followed other's suggestion by changing the folder structure plus matching the version of php on both server and which laravel supports, so in my case my server was running on php 5.4 and i was using Laravel 5.4 so i downgraded it with 4.2.
Plesk for Windows uses the IIS HTTP Server (http://www.iis.net/) for hosting and managing websites. So i configured in my "web.config" file (if it's not available create one on root ) to make it all work
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="default.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
index.php
require __DIR__.'/your_root_folder_name/bootstrap/autoload.php';
$app = require_once __DIR__.'/your_root_folder_name/bootstrap/start.php';
$app->run();
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I have tried with following code.
<IfModule mod_rewrite.c>
RewriteEngine On
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]
</IfModule>
I have replaced with blank in config file index_page but still not working and getting this error.
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.
Please help me to sort out this.
I have solved the problem. I have made web.config in root directory of codeigniter. My Code is following.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
It is working for me. I hope this will help others too.
place your .htaccess file within your codeiginter project directory then write this code in .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ project_dir_name/index.php/$1 [L]
Replace "project_dir_name" with you actual directory name in 3rd line.
If still you have problem then check your controller, method name and permission of folders and files.
I am using apache mod rewrite and i have a .htaccess rewrite statement. I would like to change over to use IIS server and would like to know if any one can give me advice on how to convert my existing .htaccess statement to iis web.config.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
Expert Advice appreciated.
For IIS 7 you would use <system.webServer><rewrite> section. There is an excellent article on translating .htaccess to web.config here
<rewrite>
<rules>
<rule name="Your Rule" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" />
</rule>
</rules>
</rewrite>
Resolved. Download url rewrite from Microsoft web platform installer. Url rewrite module can auto create the web.config when you specify the rules via their ui.