Posts

Showing posts with the label .htaccess

How can we include php files without specifying the subfolder path

How can we include php files without specifying the subfolder path Normally we use the following code to include php files inside each other: <?php include_once 'include/config.php'; // OR include 'include/config.php'; // OR include_once $_SERVER['DOCUMENT_ROOT'].'include/config.php'; // ect... ?> But the above codes only apply if the php files are in the root file. I mean, if we move our files into a subfolder. We need to make a change to the code we included in the php files. For example like this: <?php include_once 'subfolder/include/config.php'; // OR include 'subfolder/include/config.php'; // OR include_once $_SERVER['DOCUMENT_ROOT'].'/subfolder/include/config.php'; // ect... ?> What I'm saying is that when we move our php files into the subfolder, then include_once want to see subfolder name like ( include_once 'subfolder/include/config.php'; ). This is a challenging s...

rewrite subfolder doesn't work

rewrite subfolder doesn't work Following rule doesn't work for subfolder rewriting. RewriteRule ^cat/([0-9a-zA-Z]+) cat.php?id=$1 RewriteRule ^cat/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) cat.php?id=$1&sid=$2 For example With this rule <?php $id='News'; $sid='Politics'; ?> <a href="cat/<?php echo $id?>/<?php echo $sid?>">..</a> In next page, while echoing $_GET['sid'] , it doesn't work $_GET['sid'] Notice: Undefined index: sid in ... But this rule RewriteRule ^cat/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) cat.php?id=$1&sid=$2 works, if only there is two querystring parameters <a href="cat/<?php echo $id?>/<?php echo $sid?>">..</a> but it generate ERROR 500 if there is only one parameter ERROR 500 <a href="cat/<?php echo $id?>>..</a> 1 Answer 1 Try with below, R...

rewrite url for videos with dynamic links

rewrite url for videos with dynamic links I have a video sharing website where users upload their videos and get a link for the video, here is an example of the video link: http://example.com/user/files/index.php?id=123&name=abc the Url I want is http://example.com/user/f/123/abc Id parameter is the identifier (id) of the video and the name is optional.If a user forgot to write the name parameter ,then the URL will be like this http://example.com/user/f/123 but it should still reach the destination . What should I put in my htaccess to achieve this? 1 Answer 1 Try this in your Root/.htaccess file Root/.htaccess RewriteEngine on RewriteBase / #if the Requested filename is not a directory RewriteCond %{REQUEST_FILENAME} !-d #if the Requested filename is not a file RewriteCond %{REQUEST_FILENAME} !-f #if above conditions are true then rewrite the url RewriteRule ^user/f/([0-9]+)/([a-zA-Z0-...