So we have a php page www.example.com with a button which redirects to www.subdomain.example.com
We are facing following issues with sub domain and htaccess:
When we use button the
media queries and favicons do not work
When we user button where the sub domain code is, the URL masking doesn't work (but media queries and favicons work perfectly)
We have HTACCESS configured such that .php is hidden in URL and www.example.com/folder/index2 is masked by www.subdomain.example.com
Throughout the sub domain title also doesn't work
We have following setup in GoDaddy:
subdomain -> www.subdomain
www.subdomain -> www.example.com/folder/index2
example.com -> www.example.com
The sub domain code is in example.com/folder/
We are trying to understand how the mapping works as code is working perfectly fine without sub domain but messes up when we redirect the URL.
Main index file
<html>
<head>
<?php
$dir = "favicons/";
$files = array();
if ($handle = opendir($dir))
{
while (false !== ($file = readdir($handle)))
{
$files[] = $file;
}
}
$icon = $files[rand(2,count($files)-1)];
echo '<LINK REL="shortcut icon" HREF="favicons/'.$icon.'">';
?>
<meta charset="utf-8">
<title>Title</title>
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="assets/css/main2.css" rel="stylesheet">
</head>
<body>
<div class="center">
<img href=""src="images/bg.jpg">
<br>
<br>
<button class="bt">button</button>
</div>
<script src="assets/js/jquery.min.js">
</script>
<script src="assets/js/jquery.poptrox.min.js">
</script>
<script src="assets/js/skel.min.js">
</script>
<script src="assets/js/main.js">
</script>
</body>
</html>
Index2 file which is in the folder pointed by subdomain
<!DOCTYPE html>
<html>
<head>
<?php
$dir = "../favicons/";
$files = array();
if ($handle = opendir($dir))
{
while (false !== ($file = readdir($handle)))
{
$files[] = $file;
}
}
$icon = $files[rand(2,count($files)-1)];
echo '<LINK REL="shortcut icon" HREF="../favicons/'.$icon.'">';
?>
<meta charset="utf-8">
<title>Title</title>
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="../assets/css/main1.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
</head>
<body>
<h1>random text</h1>
<br>
<script src="assets/js/jquery.min.js">
</script>
<script src="../assets/js/jquery.poptrox.min.js">
</script>
<script src="../assets/js/skel.min.js">
</script>
<script src="../assets/js/main.js">
</script>
</body>
</html>
HTACCESS file
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo/ to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
ErrorDocument 400 www.example.com/Error-404
ErrorDocument 401 www.example.com/Error-404
ErrorDocument 403 www.example.com/Error-404
ErrorDocument 404 www.example.com/Error-404
ErrorDocument 500 www.example.com/Error-404
Related
I am trying to add css file dynamically in ejs tempelate.
I know how to include ejs file but not getting how to add css file dynamically.
Code :-
Index.js
router.get('/', function(req, res, next) {
res.render('template', { title: 'abc',page:'index',cssa:'home'});
});
template.ejs
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css">
<!-- Here I want to add home.css file -->
</head>
<body>
<!-- including my ejs file -->
<%- include(page) %>
</body>
</html>
I tried :
<link rel="stylesheet" type="text/css" href="/stylesheets/\<%= cssa %>\" >
<% include %><%= cssa %><% .css %>
Goal:
to pass the server side received variable(cssa) in stylesheet source.
Don't need to concat the css path and variable, you can also do it as follows:
<link rel='stylesheet' href='/stylesheets/<%= yourVariableName %>.css' />
Method to include :
<% var css_link = '/stylesheets/' + cssa + '.css'; %>
<link rel="stylesheet" type="text/css" href="<%= css_link %>" >
Credit goes to #SpiRT
Alternatively :
<link rel="stylesheet" type="text/css" href="/stylesheets/<%=cssa%>.css">
I've found it most convenient to inject custom css scripts through an array which can then be processed in the ejs template.
This method would allow you to render any amount of CSS files that are additionally required (example, you have a site that uses 1 standard css across all pages but have 1 or 2 page specific ones which can then be included in the model passed through the ejs renderer to that specific page/route).
In the example it's a given that the css files are in the same folder, however that can be changed to each one's liking:
router side:
router.get( ... {
model = {};
model.Stylesheets = [];
model.Stylesheets.push("stylefile");
res.render("view",{model:model});
});
with the custom stylesheets being pushed though to the view, then the ejs files can be something like:
<%
var customStylesheets = "";
model.Stylesheets.forEach(function(style){
customStylesheets+='<link type="text/css" rel="stylesheet" href="css/'+style+'.css">';
})
%>
<!DOCTYPE html>
<html>
<head>
<title><%= model.title %></title>
<link type="text/css" rel="stylesheet" href="css/standard.css">
<%- customStylesheets %>
...
</head>
.htaccess
# Remove .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
# Return 404 if original request is .php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]
This works fine, but how to modify the code so that a language switch based on this code works?
Currently it does the following:
localhost/index = OK
localhost/index.php = OK (404 error)
but when you press the button
EN
it will change the address as follows
localhost/index => localhost/index.php?la=en = FAIL (404 page)
which throws 404 error as well. Is it possible to prevent it? Would it just prevent the .php from being added before the query string? I want the language switch to work as well, is it possible? Any ideas?
Language switch:
<?php
session_start();
if($_GET['la']){
$_SESSION['la'] = $_GET['la'];
header('Location:'.$_SERVER['PHP_SELF']);
exit();
}
switch($_SESSION['la']){
case "eng":
require('lang/eng.php');
break;
case "fre":
require('lang/fre.php');
break;
case "ger":
require('lang/ger.php');
break;
default:
require('lang/eng.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $lang['index-title'];?></title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="langSelect">
<img src="flags/eng.png" alt="<?=$lang['lang-eng'];?>" title="<?=$lang['lang-eng'];?>" />
<img src="flags/fra.png" alt="<?=$lang['lang-fre'];?>" title="<?=$lang['lang-fre'];?>" />
<img src="flags/ger.png" alt="<?=$lang['lang-ger'];?>" title="<?=$lang['lang-ger'];?>" />
</div>
<div id="cont">
<p><?=$lang['index-welcome'];?></p>
<p><?=$lang['index-text-1'];?></p>
</div>
</div>
</body>
</html>
SOLVED!
Replace:
header('Location:'.$_SERVER['PHP_SELF']);
With:
header('Location:'. str_replace(".php", "", $_SERVER['PHP_SELF']));
The problem is at : header('Location:'.$_SERVER['PHP_SELF']);
The $_SERVER["PHP_SELF"] is a super global variable that returns the
filename of the currently executing script.
Change it to:
header('Location:'. str_replace(".php", "", $_SERVER['PHP_SELF']));
which remove the extension from the string.
Hope it helps.
Hello my friend i am working on captcha validation but i can not get example page when i created
this is my .htaccess code
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
and this is my example.php file which is in views folder
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script>
$(document).ready(function () {
$('.refreshCaptcha').on('click', function () {
$.get('<?php echo base_url().'captcha / refresh'; ?>', function (data) {
$('#captImg').html(data);
});
});
});
</script>
</head>
<body>
<h4>Submit Captcha Code</h4>
<p id="captImg">
<?php echo $captchaImg; ?>
</p>
<p>Can't read the image? click
here to refresh.</p>
<form method="post">
Enter the code :
<input type="text" name="captcha" value="" />
<input type="submit" name="submit" value="SUBMIT" />
</form>
</body>
</html>
but when i wire localhost/capcode/example, it shows foo:bar how can i fix this?
Can anyone tell me how it is possibile that the following layout in a Rails 4 app
# app/views/layout/login.html.erb
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>PIPPO</title>
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black-translucent" name="apple-mobile-web-app-status-bar-style">
<meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0" />
<link href="/assets/login.css" media="all" rel="stylesheet" />
<script src="/assets/login.js"></script>
<%= csrf_meta_tags %>
</head>
<body>
<div class="main-content">
<%= yield %>
</div>
</body>
</html>
With the following controller
class SessionsController < ApplicationController
layout 'login'
...
def destroy
Session.find(session[:id]).close
reset_session
respond_to do |format|
flash[:success] = t('sessions.logout')
format.html { redirect_to login_url }
end
end
end
and routes
...
get 'login', to: 'sessions#new', as: 'login'
get 'logout', to: 'sessions#destroy', as: 'logout'
...
produces the following HTML once I click on <%= link_to 'logout', logout_path %>?
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>PIPPO</title>
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black-translucent" name="apple-mobile-web-app-status-bar-style">
<meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0" />
<link href="/assets/application.css" media="all" rel="stylesheet" />
<script src="/assets/application.js"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="l9+umk+wjpXY4UFiKEeuQkGgMvjbbZ2uDxyJHowTJFo=" name="csrf-token" />
</head>
Am I missing anything here? It is two days I'm trying to figure this out.
Why is it using the head from the main layout instead of the one in login?
Thanks for your help.
UPDATE - Forgot to mention my log file states:
Rendered sessions/new.html.erb within layouts/login (1.4ms)
As per the layout name given in the question, i.e.,
app/views/layout.login.html.erb
There are couple of things wrong here:
layouts should be placed in app/views/layouts folder
File name should be login.html.erb and not layout.login.html.erb
In your case, Rails could not find login.html.erb in app/views/layouts, it rendered the default layout app/views/layouts/application.html.erb.
I would like to develop an external website using Facebook Connect instead of an own login and registration process.
On the first page (index.php) I have the following code for the login button:
<fb:login-button v="2" size="large" autologoutlink="false" onlogin="window.location='/index.php'">Connect with Facebook</fb:login-button>
For authentification, I use this library for PHP.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="de" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta http-equiv="content-style-type" content="text/css" />
</head>
<body>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/de_DE" type="text/javascript"></script><script type="text/javascript">FB.init("XYZ");</script>
<?php
error_reporting(E_ALL);
include_once '/XYZ/facebook.php';
include_once 'lib.php';
include_once 'config.php';
$facebook = new Facebook($api_key, $secret);
$user = $facebook->require_login();
$loggedin = FALSE;
if (isset($user)) {
if ($user != '') {
echo '<p>Hello <fb:name firstnameonly="true" uid="'.$user.'" useyou="false" /></p>';
echo '<p>Log out</p>';
$loggedin = TRUE;
}
}
if ($loggedin == FALSE) {
echo '<p><fb:login-button onlogin="window.location=\'/\'"></fb:login-button></p>';
}
?>
</body>
</html>
Unfortunately, it doesn't work yet. What is wrong here?
When I want to access this page, I'm redirected to http://www.facebook.com/login.php?api_key=XYZ&v=1.0&next=XYZ where I have to log in. Then, being logged in to Facebook, I'm redirected again. This time, I get to https://login.facebook.com/login.php?auth_token=XYZ
try
$user = $facebook->get_loggedin_user();
instead of
$user = $facebook->require_login();
require_login() will force you to the facebook login.php