How can I rewrite a rule for the url
navi.php?a=815&lang=eng
and a meta title
How can I post a Video
into
/en/How-can-I-post-a-Video
Can the Meta Title be fetched somehow to add it to url?
Instead of passing the params in the url, you need to form a url with meta tag title. From the url take the arguements and match with the database and get the result data. This is how the .htaccess will work.
You can make a rewrite rule like so:
RewriteRule ^(.*)$ index.php?params=$1 [NC]
This will make your actual php file like so:
index.php?params=value¶m=value
And your actual URL would be like so:
http://url.com/params/param/value/param/value
And in your PHP file you could access your params by exploding this like so:
<?php
$params = explode( "/", $_GET['params'] );
for($i = 0; $i < count($params); $i+=2) {
echo $params[$i] ." has value: ". $params[$i+1] ."<br />";
}
?>
Related
I must make a website with PHP and I choose to use Slim and Twig. But my superiors don't want me to use a virtual host. So I'm having trouble when I test the website with MAMP because the site is on a subdirectory, like http://localhost:8888/subdir.
When I try to access an asset, I can't use absolute path because it would force me to write /subpath/path/to/asset. But when we will deploy the application, there will be no subpath. How can I root the website as if there would be a virtual host?
You can see some of my code below:
index.php
<?php
require 'vendor/autoload.php';
include 'database.php';
use app\controller\ConfigController;
$app = new \Slim\Slim();
$app->get('/', function () {
echo "accueil";
})->name("root");
$app->group('/Admin', function () use ($app) {
$app->get("/", function (){
$ctrl = new ConfigController();
$ctrl->index();
})->name("indexAdmin");
});
.htaccess (in localhost:8888/subdir)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
ConfigController (called function)
public function index() {
$loader = new \Twig_Loader_Filesystem("app/view/Admin");
$twig = new \Twig_Environment($loader);
$template = $twig->loadTemplate('Index.twig');
echo $template->render(array(
'css' => "admin.css"
));
}
template called by Twig environment
<!doctype html>
<html lang="fr">
<head>
<link rel="stylesheet" type="text/css" href="/app/assets/stylesheets/{{ css }}">
</head>
<body>
[...]
When I search on Google and Stack Overflow, everyone said to make a virtual host, but I can't. Would there be another solution?
If you are using the slim/views package to integrate Twig in the application you are writing, it's possible to add the TwigExtension in that package to your Twig instance and use the siteUrl function for your assets. This way:
<link rel="stylesheet" href="{{ siteUrl('path/to/asset/style.css') }}">
If you're not using that package, you can create your own function to get the application URL. Something like this:
function siteUrl($url) {
$req = Slim::getInstance()->request();
$uri = $req->getUrl() . $req->getRootUri();
return $uri . '/' . ltrim($url, '/');
}
Ok so here is the issue. I use a cms to run a ecommerce website. It uses a mobile site addon when the user is on a phone or ipad. I want to redirect a specific url, but only when in mobile. I would like to keep the url the same for desktop.
example:
Redirect /desktop-categories/ site.com/mobile-categories
How do I do this and specify to only redirect when user is on mobile?
First you'll need to determine if their browser is a web browser on a mobile device or not. Because mobile phones typically have a small screen width, you can redirect visitors to your mobile site if they have a screen width of less than or equal to 800 pixels.
Javascript window.location Method 1
<script type="text/javascript">
if (screen.width <= 800) {
window.location = "http://m.domain.com";
}
</script>
You can use a .htaccess redirect to transfer visitors based upon the MIME types the browser supports. For example, if the user's browser accepts mime types that include WML (Wireless Markup Language), then most likely it is a mobile device.
.htaccess URL rewrite redirects 1
RewriteEngine On
# Check for mime types commonly accepted by mobile devices
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ http://m.domain.com%{REQUEST_URI} [R,L]
Redirecting Mobile Users by Screen Size Instead of Device Type 2
var Responsive = {
maxPhoneWidth: 775,
maxTabletWidth: 925,
//REDIRECT BASED ON CONFIGURABLE MAX WIDTH THRESHOLD
maxWidthRedirect: function (maxWidth, url) {
var viewport = this.getWindowSize();
//ADD EXCLUSION IN HASH IN CASE DESKTOP VIEWING IS INTENDED
if (window.location.hash != '#desktop' && viewport.width < maxWidth)
window.location.href = url;
},
//REDIRECT BASED ON RECOMMENDED PHONE WIDTH THRESHOLD
mobileRedirect: function (url) {
this.maxWidthRedirect(this.maxPhoneWidth, url);
},
//REDIRECT BASED ON RECOMMENDED TABLET WIDTH THRESHOLD
tabletRedirect: function (url) {
this.maxWidthRedirect(this.maxTabletWidth, url);
},
//DETERMINE CROSS-BROWSER SCREEN SIZE
getWindowSize: function () {
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight || e.clientHeight || g.clientHeight;
return { width: x, height: y };
}
};
You can see the code in action at the following link and trying different browser sizes.
References
How to redirect your website to its mobile version
Redirecting Mobile Users by Screen Size Instead of Device Type
My client wants his videos hidden and not having the possibility to be downloaded or copied (or at least to make it difficult to do).
I'm trying to use flowplayer secure streaming, but I cannot make it work!
I'm getting this error:
200, Stream not found, NetStream.Play.StreamNotFound, clip: '[Clip]
'secure/ad722768cfa6f10b51b7e317c8dd1ca4/1417957647/v.mp4"
It says the video was not found, but it's placed on secure/v.mp4 as it should (right?)
UPDATE1
I forgot to mention that I have the required apache rewrite rule inside secure folder…
secure/.htaccess
RewriteEngine on
RewriteBase /secure
RewriteRule ^(.*)/(.*)/(.*)$ video.php?h=$1&t=$2&v=$3
RewriteRule ^$ - [F]
RewriteRule ^[^/]+\.(flv|mp4)$ - [F]
UPDATE2
I did it! It was a dumb simple thing:
I was testing with easyphp webserver, and the url was localhost/v/index.html
I did a test moving all the content from /v folder to the root and it worked!
And now I learned in htaccess I need to put the full path on RewriteBase starting from the root, in my case I needed to set this:
RewriteBase /v/secure
The codes:
index.html
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="flowplayer-3.2.13.min.js"></script>
<script>
$(document).ready(function() {
$f("player", "flowplayer-3.2.18.swf", {
plugins: {
secure: {
url: "flowplayer.securestreaming-3.2.9.swf",
timestampUrl: "sectimestamp.php"
}
},
clip: {
baseUrl: "secure",
url: "v.mp4",
urlResolvers: "secure",
scaling: "fit",
}
});
});
</script>
</head>
<body>
<div id="player"></div>
</body>
sectimestamp.php
<?php
echo time();
?>
secure/video.php
<?php
$hash = $_GET['h'];
$streamname = $_GET['v'];
$timestamp = $_GET['t'];
$current = time();
$token = 'sn983pjcnhupclavsnda';
$checkhash = md5($token . '/' . $streamname . $timestamp);
if (($current - $timestamp) <= 2 && ($checkhash == $hash)) {
$fsize = filesize($streamname);
header('Content-Disposition: attachment; filename="' . $streamname . '"');
if (strrchr($streamname, '.') == '.mp4') {
header('Content-Type: video/mp4');
} else {
header('Content-Type: video/x-flv');
}
header('Content-Length: ' . $fsize);
session_cache_limiter('nocache');
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
$file = fopen($streamname, 'rb');
print(fread($file, $fsize));
fclose($file);
exit;
} else {
header('Location: /secure');
}
?>
I already tried this > Flowplayer Secure Streaming with Apache but I also get the error above.
Does anyone use flowplayer secure streaming? What am I doing wrong?
I figured out what was wrong, in htaccess you need to put the full path on RewriteBase starting from the root, in my case I needed to set this:
RewriteBase /v/secure
I try to load a file with node.js.
In my view, I've got a button :
doctype 5
html(ng-app="lineApp")
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
p filename: #{filename}
button(onclick="location.href='/app/#{filename}'") click me
The page display a paragraph with filename: C:\users\username\my filename.txt.
When I click on the button, the URL is something like http://localhost:8080/app/C:usersusernamemy%20filename.txt
So when I try to retrieve the parameter
exports.appli = function (req, res) {
var filename = req.params.filename;
//....
});
};
with the server side call :
app.get('/app/:filename?', routes.appli);
I got an invalid filename. My question is then, how to pass a file path as a parameter in URL ?
This is a problem with the slashes acting as escape characters.
The first time you pass the string to the client, any escaped slashes (ex: c:\\users\\username\\my file.txt) are converted to single slashes.
When you use href.location, the slashes act as escape characters a second time...which is why they drop out when you try to call the server using it.
You could:
Create two variables to pass to the jade template, one the filename as-is and the other an HTML encoded string
pass the variables to the jade template:
For example, based upon your original jade:
body
p filename: #{filename}
button(onclick="location.href='/app/#{encodedFilename}'") click me
I want to redirect a link from
www.example.com/ex.php?name=andy
to
www.andy.example.com
Can you give me the code please
Why use .htaccess? You can do that with PHP.
<?php
$url = 'http://www.'. $_GET['name'] .'.example.com';
header('Location: '. $url);
?>
Just make sure you don't output any text before using header().
To get the name from the subdomain URL do the following.
<?php
$new_url = $_SERVER["SERVER_NAME"];
$url_parts = explode('.', $new_url);
echo 'Name is: '. $url_parts[0];
?>
james.example.com results in "Name is: james".