i have problem with an ajax.
When i execute my ajax call the response of the page is "500 internal server error".
I suppose is a problem derivated from .htaccess.
This is my code:
Ajax code:
$.ajax({
method: 'POST',
url: "/php/function_ajax.php",
data: "action=doSomething",
success: function(result){
alerrt('Yep, it\'s work!');
},
error: function(request, status, error){
alert(error+' - '+status+' - '+request);
return false;
}
});
This is my .htaccess
ErrorDocument 404 /page-not-found
Options +FollowSymLinks
RewriteBase /
RewriteEngine On
RewriteRule ^font - [L,NC]
RewriteRule ^images - [L,NC]
RewriteRule ^js - [L,NC]
RewriteRule ^php - [L,NC]
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link
RewriteCond %{REQUEST_FILENAME} !-l
and then the rewrite condition for my htaccess.
If i remove the condition "RewriteRule ^php - [L,NC]" it will return "page-not-found".
Someone can help me? Thanks.
alerrt('Yep, it\'s work!');
two r's in alert might be your problem
Related
This is vuejs and laravel project. I am facing issue in backend when I type complete url with admin then it says not found. This is happening because I was getting 404 laravel error in refresh inside components. So I used the below route in web.php
Route::get('/{any?}', function () {
return view('index');
});
In Vuejs, I am using the following:
I am using webhistory in route
I am also using fallback route
{
path: "/:pathMatch(.*)",
name: "NotFound",
component: NotFound,
},
backend is based on laravel. Here is the .htaccess data
<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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
laravel route
I tried the below one:
Route::get('/{any?}', function () {
return view('index');
});
and this one also
Route::get('/{any}', function(){
return view('index');//pointing to the index file of the frontend
})->where('any', '.*');
Route::get('/admin',[AdminAuthController::class,'Create'])->name('create.login');
Route::post('/admin/login',[AdminAuthController::class,'Store'])->name('store.login');
Please suggest
I am using laravel 8 php 7.4. All route working fine on Local machine. But on Live serve Ubuntu 20.04 only one route is working that is / route.
My .htaccess file is in public folder and its content is
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [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]
</IfModule>
and my route file is
Route::get('/', function () {
return view('auth.login');
});
Auth::routes(['verify' => true]);
Route::post('user/login', [App\Http\Controllers\UserController::class, 'login'])->name('user.login');
Route::post('user/registration', [App\Http\Controllers\UserController::class, 'register'])->name('user.registration');
Route::get('/redirect', [\App\Http\Controllers\SocialAuthGoogleController::class, 'redirect']);
Route::get('/auth/google/callback', [\App\Http\Controllers\SocialAuthGoogleController::class, 'callback']);
Route::middleware(['auth', 'verified'])->group(function () {
Route::get('logout', [App\Http\Controllers\Auth\LoginController::class, 'logout'])->name('logout');
Route::get('show/energy/service/{id}', [\App\Http\Controllers\EnergyServiceController::class, 'show'])->name('show.energy.service');
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('student', [\App\Http\Controllers\StudentController::class, 'index'])->name('student');
Route::post('student/add', [\App\Http\Controllers\StudentController::class, 'store'])->name('student.add');
Route::get('student/edit/{id}', [\App\Http\Controllers\StudentController::class, 'edit'])->name('student.edit');
Route::post('student/update', [\App\Http\Controllers\StudentController::class, 'update'])->name('student.update');
Route::get('student/delete/{id}', [\App\Http\Controllers\StudentController::class, 'delete'])->name('student.delete');
});
When I visit on any link This page appear
enter image description here
How can i resolved this thanks in advance
I'm trying to redirect http to
https://www.example.com
in laravel 5.2
trying to do it using middlware Please see code
In karnel.php
\App\Http\Middleware\HttpsProtocol::class,
middlware
public function handle($request, Closure $next)
{
$url = 'https://www.example.com';
if (!$request->secure()) {
return redirect()->secure($url);
}
return $next($request);
}
but getting error
ERR_TOO_MANY_REDIRECTS
And when try to do it using .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]
# require SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
it will redirect to
https://www.www.example.com
What i want is if anyone type domain.com then it will automatically redirect to
https://www/example.com
in laravel 5.2
I am using Cloudways server in order to redirect my http site to https i have install the certificaiton and now its working but if i am using
myhost.com in url baar the sites open and the site not redirect into https://www.myhost.com
in order to do force ssl i am using this code
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTP_HOST} ^myhost\.com$ [NC]
RewriteRule ^ https://www.myhost.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
RewriteRule ^index\.php(/(.*))?$ myhost.com/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
However it is also not working and give me the error of too many redirects i am also using hooks ssl code
<?php
function redirect_ssl() {
$CI =& get_instance();
$class = $CI->router->fetch_class();
$exclude = array('client'); // add more controller name to exclude ssl.
if(!in_array($class,$exclude)) {
// redirecting to ssl.
$CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']);
if ($_SERVER['SERVER_PORT'] != 443) redirect($CI->uri->uri_string());
} else {
// redirecting with no ssl.
$CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']);
if ($_SERVER['SERVER_PORT'] == 443) redirect($CI->uri->uri_string());
}
}
it is also not working somebody please suggest me what can i do.
Try this much less complex solution that works for most CI installations.
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
With the above in place, there is no need for the hook routine. Just set config['base_url'] = "https://myhost.com/"; and be done with it.
I am new to the Laravel while I reading the documentation I had a problem under routing.. it shows we can pass verifiable like this,
Route::get('user/{id}', function ($id) {
return 'User '.$id;
});
here what is the user is it Controller or veritable name. I tried to pass the verbal like below but it is getting error
my route code is ,
Route::get('/{id}', function ($id) {
echo 'ID: '.$id;
});
Your route is correct
Route::get('/{id}', function ($id) {
echo 'ID: '.$id;
});
i have tested it and its working fine
Can you check .htaccess file under public folder.
<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>
Also make sure about laravel project folder name is spelled correctly
As you can see in the url field you trying to get to public/32 and you should try to request such a url:
http://localhost/blog-laravel/public/user/32