.htaccess config for search bot crawling - php

Am build a web app with angularjs and my public root looks like this
-assets
-snapshots
-snapshots/article/
-snapshots/sections/
-snaphosts/index.html
.htaccess
and am using phantomjs to generate snapshots from siteamp, my htaccess look this like this
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# angular seo
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/?(.*)$
RewriteRule ^(.*)$ /snapshots/%1 [NC,L]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
when i try to test the snapshots using the url http://xyx.com/?_escaped_fragment_=/section/news i get http://xyx.com/?_escaped_fragment_=/section/news#!/ instead of http://xyx.com/snapshots/section/news.html as expected.
I figure my .htaccess config could be wrong, am not really good at htaccess configs.
Any help will be appreciated.

Related

how to redirect to the public folder

When filling on hosting, I faced the problem that you can not select the start folder of the opening. When opening a link юhttps://my-domen/ this opens
to get to the site, enter /public
how to make sure that when you open the site, the public folder is immediately opened on the hosting so you can not configure it . Can I use htaccess or something else? If this helps then the laravel files are a clean project
htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# 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]
</IfModule>
In your root folder use this .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
In the public folder use the new clean laravel .htaccess file

Unable to get .htaccess to do 301 redirects correctly in a Laravel app

I got a URL Canonicalization issue and I want to redirect https://www.barreau.co/ar to https://barreau.co/ar
Please note that the following .htaccess code redirects https://www.barreau.co/ to https://barreau.co/ perfectly, but not with the /ar or /en that the Laravel multilanguage applications add.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.barreau\.co\/ar$
RewriteRule ^/?$ "http\:\/\/barreau\.co\/ar" [R=301,L]
# 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]
How can I make both https://www.barreau.co/ and https://www.barreau.co/ar redirect to non-www URLs correctly?
There's need to specify the locale imo.
Can you try this?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
I tried it in a local environment with a fresh Laravel installation. It works fine. Make sure you also have mod_rewrite enabled and to restart your apache after doing the change.

request exceeded the limit of 10 internal redirects laravel 5.5

I have a problem when uploading a new laravel 5.5 project. When I alter the htaccess in the public_html folder on my server it keeps redirecting. However this problem wasnt there on laravel 5.0. Here's my htaccess from the public_html folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
And here's the htaccess in the public folder:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# 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]
</IfModule>
Any suggestions on how to solve this problem?
Beside the fact that it is really not good idea to put a Laravel project in your Document Root, you have a problem with your htaccess file in your Root directory.
Additional I would at least protect all files in your root folder from direct access:
<IfModule mod_rewrite.c>
RewriteEngine On
# Fake 404 for all files in /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?[^/]+$ - [R=404,L]
# Protect rewrite loop: exclude /public
RewriteCond %{REQUEST_URI} !^/?public(/.*)?$
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>

Laravel routes and pretty urls doesn't work

I'm new in Laravel. I develop a project on my local computer and it works properly. But when I publish it to the server, I just can see the main page and pretty URLs (contain CSS files and all other directories) and Laravel routes doesn't work.
Here is my configurations:
debeian 8
apache
PHP 5.6.24-0+deb8u1
.htaccess content on laravel/public:
<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>
How can I fix this?

Remove index.php from basic auth request on php-cgi

I have a Kohana 3.3 application, and I have removed /index.php/ from the URI with some rules in an .htaccess file. Everything is working fine, until I come to use Basic Authentication. I can’t access Basic Auth from $_SERVER because the site is served with php-cgi, which is explained here.
The solution in the previous link works, though it adds /index.php/ back into the URI. I can’t seem to manage to add the new rewrite rule without the server throwing a 500.
Here are my current rewrite rules:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
Options +FollowSymlinks
RewriteEngine On
# RewriteBase /
</IfModule>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [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 .* app/index.php/$0 [PT]
RewriteRule ^(.*)$ index.php/$0 [PT,L]
RewriteRule ^$ index.php/$0 [PT,L]
And here’s what I need to add:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^Basic.*
RewriteRule (.*) index.php?Authorization=%{HTTP:Authorization} [QSA,L]
</IfModule>
How can I make this work? And is there a relatively easy way to learn how mod_rewrite works?
Try this code in your DocumentRoot/.htaccess:
DirectoryIndex index.php
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /api/
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b /index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L]
RewriteCond %{HTTP:Authorization} ^Basic.*
RewriteRule ^ index.php?Authorization=%{HTTP:Authorization} [L]

Categories