Htpasswd specific url in laravel9 - laravel-9

i need make Htpasswd on admin url
example : example.com // this this out Htpasswd
example.com/admin // this with Htpasswd
Route::prefix(env('ADMIN_NAME'))->group(function () {
Route::get('/login', [LoginController::class, 'showLoginForm'])->name('admin.login');
Route::post('/login/submit', [LoginController::class, 'login'])->name('admin.login.submit');
Route::get('/forgot', [LoginController::class, 'showForgotForm'])->name('admin.forgot');
Route::get('/logout', [DashboardController::class, 'logout'])->name('admin.logout');
am try many time using .htaccess and not work
How i can do it on admin gurd
thank you

Related

Reverse Proxy Sending 127.0.0.1 as URL, instead of external site-url.com to oauth callback

I am transferring a site from the defunct OpenShift v2, to LightSail on AWS. I have the app up and running on LightSail at localhost:3333, forwarded externally. I am able to pull up the site using the site-url.com
However, when attempting to login to the app (using Passport Facebook). The callback url is getting set to 127.0.0.1, instead of the whitelisted (facebook dev) www.site-url.com
https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1%3A3333%2Fauth%2Fwww.site-url.com%2Fauth%2Ffacebook%2Fcallback&scope=email&client_id=XXX
Relevant login code:
const appUrl = "www.site-url.com";
const callbackURL = appUrl + "/auth/facebook/callback";
passport.use(new FacebookStrategy({
clientID: clientID,
clientSecret: clientSecret,
callbackURL: callbackURL,
profileFields: ['id', 'displayName', 'email']
},
...
app.get('/auth/facebook',
passport.authenticate('facebook', { scope: ['email'] }));
app.get('/auth/facebook/callback',
passport.authenticate('facebook',{
successRedirect: appUrl + '/profile',
failureRedirect: appUrl + '/?login-failed'}
));
I added appUrl, in an attempt to fix it via server code. However, I have a feeling Apache would be better suited at fixing this.
I setup the Proxy, following these instructions, and tried all variations of 127.x/site-url.com
ProxyPass / http://127.0.0.1:3333/
# ProxyPass / http://www.site-url.com/
ProxyPassReverse / http://127.0.0.1:3333/
# ProxyPassReverse / http://www.site-url.com/
Anyone have any ideas?
Turning on PreserveHost solved the issue, Facebook is now receiving the correct callback url
PreserveHost:
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3333/
ProxyPassReverse / http://127.0.0.1:3333/
Apache config:
vim /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf
Append: Include "/home/bitnami/conf/httpd-app.conf
Start up the app using screen to avoid shutdown when SSH process is killed. Maybe try nodemon for resiliency
Thanks, #DusanBajic!

Redirecting to relative path using Laravel 4

Is it possible, in Laravel 4.1, to redirect to a relative path instead of the full path ? If we look at the UrlGenerator::to method, here what we have:
public function to($path, $extra = array(), $secure = null)
{
if ($this->isValidUrl($path)) {
return $path;
}
$scheme = $this->getScheme($secure);
$tail = implode('/', array_map('rawurlencode', (array) $extra));
$root = $this->getRootUrl($scheme);
return $this->trimUrl($root, $path, $tail);
}
This will act like this (meta-code):
mysite.com/url Redirect::to('/test'); => mysite.com/test
What I'd want it's to be redirected to a relative URL:
mysite.com/url Redirect::to('/test'); => /test
The problem it's that the company I'm working for, use a ReverseProxy to redirect all the traffic to HTTPS protocol, and with this kind of laravel redirects I keep getting redirected from HTTP to HTTPS :
call: GET http:// mysite.com
proxy: GET https:// mysite.com
redirect to login: GET http:// mysite.com / login
proxy: GET https:// mysite.com / login
submit login: POST http:// mysite.com / login
proxy: POST https:// mysite.com / login
And the problem is that the submit form fail.
Is there a possibility to redirect to the relative path and let the proxy define the root url / protocol to use ?
I'm on Laravel 4.2, I'm using Redirect::away('/test'), not sure if the function is there yet on Laravel 4.1.

Redirect loop in CI after installing SSL Certificate

I just installed ssl certificate on my site to change the URL from http:// to https:// Everything is complete and i also added a code in my httpd.conf file to automatically add https :// to the UR So the connection is always secure.
However I am facing a problem when i try to login into the Admin Panel. It Goes in a redirect Loop and the webpage gives me a "This webpage has a redirect loop" Error.
https://mysite.com Loads fine but https:/mysite.com/admin goes into a redirect loop.
site is built up using codeigniter Framework for php.
Please Help.
I added this code to my httpd.conf file
#
# Redirect http Request to https
# The lines below are used to redirect http request to https
#
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
Open config file from location application/config/config.php and enable or set hooks to true like this:
$config['enable_hooks'] = TRUE;
Then create a new file named hooks.php inside the config folder (i.e. application/config/hooks.php) and add the following code in it:
$hook['post_controller_constructor'][] = array(
'function' => 'redirect_ssl',
'filename' => 'ssl.php',
'filepath' => 'hooks'
);
Now create a new directory named hooks inside the application folder (i.e. application/hooks) and then create a new file named ssl.php inside the hooks folder (i.e. application/hooks/ssl.php).
Add the following code in the ssl.php file:
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());
}
}

returnurl() always return index.php in yii

I created a module Admin in yii.
If I request any page in this module before login it will redirect to login page. But after successful login it rediect to the site/index. This is the code for redirection.
if($model->validate() && $model->login())
{
$this->redirect( Yii::app()->user->returnUrl );
}
when I print Yii::app()->user->returnUrl, it shows /
thanking you for help.

Redirect full website address to another address - Apache

How can I redirect the following via a virtual host:
http://www.surveys.abc.com/index.php?sid=14414&newtest=Y&lang=en
to
http://www.abc.com
You don't really need to use Apache's mod_rewrite for that.
You can tweak your PHP code in index.php to look for those appropriate values in $_GET and then do the PHP redirect like this:
if (isset($_GET['sid']) && ($_GET['sid']==14414) && isset($_GET['newtest']) && ($_GET['newtest']==Y) && isset($_GET['lang']) && ($_GET['lang']=="en") ) {
header( 'Location: http://www.abc.com' );
}