I have this folder structure
--laravel
----public
------index.php
------uploads
--------image.jpg
--angular
----dist
------index.html
I want 3 things
1) http(s)://www.domain.com/public/uploads/image.jpg goes to laravel->public->uploads->image.jpg
2) http(s)://www.domain.com/api/test goes to laravel->public->index.php
3) http(s)://www.domain.com/every_other_url goes to angular->dist
I have create this .htacces file
DirectoryIndex index.html index.htm default.htm index.php index.php3 index.phtml index.php5 index.shtml mwindex.phtml
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^api/(.*)$ laravel/public/$1 [L]
RewriteRule ^public/(.*)$ laravel/public/$1 [L]
RewriteCond %{REQUEST_URI} !^/angular/dist/
RewriteRule ^(.*)$ /angular/dist/$1
</IfModule>
First and second requirements works properly. Now I need to fix the 3rd
(I'm not using the HashLocationStrategy)
DirectoryIndex /angular/dist/index.html
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^api/(.*)$ laravel/public/$1 [L]
RewriteRule ^public/(.*)$ laravel/public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.(.*) /angular/dist/$1.$2 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /angular/dist/index.html [NC,L]
</IfModule>
Related
I am facing an issue that Laravel is getting my folder as a URL while in crawling. I have using redirection but still the error is present.
<IfModule mod_rewrite.c>
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>
I have tried this i htaccess
I have a default laravel 8 project. I can only access my files if i use '/public/' to acess the route,and i do NOT want that. i just want to go 'localhost/ProjectName/Route' and not 'localhost/ProjectName/public/Route'.
I have tried changing .htacess, sending it to root,renaming server.php to index.php and a million other solutions i have found on the web.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization MemberHeader
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]
# Remove public URL from the path
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
this is my htacess
Make sure your webs server configuration has the public directory set as the root folder rather than the root folder of the Laravel project.
Replace your .htaccess file with following code. Please note, you don’t need to rename server.php to index.php or anything to remove /public name. Just using following code in your .htaccess file and you are good to go.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Result:
website.com/public/route to website.com/route
If you are trying to run laravel project in sub-folder within the root directory, above code won't work. Instead, use following code in your .htaccess file.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</IfModule>
Result: website.com/sub-project/public/route to website.com/sub-project/route
Inside the public_html folder their are numerous folders of other domains and a .htaccess file. I need to edit the .htaccess file of a specific domain and not effect the other domains.
Here is how last few entries of the .htaccess file looks like
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I want to add this piece of code after RewriteBase but I don't want to screw up the other domains.
RewriteRule ^page/(.*) ads/page/$1 [R=301,L]
RewriteRule ^page/(.*)/ ads/page/$1/ [R=301,L]
How do I solve this?
You can specify different .htaccess files to use using AccessFileName in your VirtualHost directive:
<VirtualHost <ip address>:80 >
# ...
AccessFileName .htaccess.some_domain
I'm having problem with redirecting.
How do i redirect localhost/volleyball to localhost/volleyball/index.php?
because it displays my directory i want it to point to index.php. Btw, i'm using Codeigniter2.2
here's my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /volleyball/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
i got the answer, i added:
DirectoryIndex index.php
Im a complete beginner with Apache re-writes.
Im trying to get example.com/forum to be example.com/index.php?page=forum
Here is my rewrite file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/forum$ index.php?page=forum
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteRule ^(.*)$ index.php?page=$1
This should work for you.