PHP - Mod_rewrite Folder To Variable
Hi friends,
I have to transform this url domain.com/main/folder1/folder2/folder3 to
domain.com/get.php?var1=folder1&var2=folder2&var3=folder3
How can i do it with htaccess.
Thank u
Edited by exarhis, 08 July 2014 - 04:42 AM. Similar TutorialsHello everyone, I can't connect to IRC at the moment :/ Anyways, I'm creating a site, where I use 'pretty' urls, I'm rewriting etc contact.php to contact/ At the moment I'm on localhost/website/ and everything is working great! but as soon as I go to localhost/website/contact/ all the styles, and images, and JS is missing :/ This is how my RewriteEngine is at the moment: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ $1.php [L,QSA] if ($d = opendir("uploads")) { while ($file = readdir($d)) { if ($file != "." && $file != ".." ) // if( is_file($file) ) { $files[] = $file; } } closedir($d); }if ($file != "." && $file != ".." $file != ???????? ) just a bit stuck here I am attempting to us glob to display contents of a users folder using a session variable. Example: I have a session variable called department Code: [Select] $row_fullname['department']; In department I have the name of the department the user belongs to such as: office, plant, maintenance, and groundskeeping I created a folder called docs inside of docs there are 4 subfolders called office, plant, maintenance, and groundskeeping I found this code which will display the contents of the folder: Code: [Select] <?php $files = glob( './docs/office/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/office/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?> The above code works fine, but I would like it to only display the contents of a departments folder only if the user is part on that department. Here is an example that I know is completely wrong but it may help explain what I am trying to do. Code: [Select] <?php ]<?php $files = glob( './docs/echo $row_fullname['department'];/*.*' ); foreach ( $files as $file ) { echo '<a href="./docs/echo $row_fullname['department'];/' . basename( $file ) . '"target="_blank">' . basename( $file ) . '</a><br />'; } ?>Thanks for your time I got this script: But it give me error, file_get_contents cannot open stream. I need to add the FTP connection with user/pass paramaters. then look in set http url, to get the file contents(images) and transfer to ftp server location. Can Anyone take alook and tell me if I am going down the right path and how to get there. Please Code: [Select] function postToHost($host, $port, $path, $postdata = array(), $filedata = array()) { $data = ""; $boundary = "---------------------".substr(md5(rand(0,32000)),0,10); $fp = fsockopen($host, $port); fputs($fp, "POST $path HTTP/1.0\n"); fputs($fp, "Host: $host\n"); fputs($fp, "Content-type: multipart/form-data; boundary=".$boundary."\n"); // Ab dieser Stelle sammeln wir erstmal alle Daten in einem String // Sammeln der POST Daten foreach($postdata as $key => $val){ $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n"; } // Sammeln der FILE Daten if($filedata) { $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$filedata['name']."\"; filename=\"".$filedata['name']."\"\n"; $data .= "Content-Type: ".$filedata['type']."\n"; $data .= "Content-Transfer-Encoding: binary\n\n"; $data .= $filedata['data']."\n"; $data .= "--$boundary--\n"; } // Senden aller Informationen fputs($fp, "Content-length: ".strlen($data)."\n\n"); fputs($fp, $data); // Auslesen der Antwort while(!feof($fp)) { $res .= fread($fp, 1); } fclose($fp); return $res; } $postdata = array('var1'=>'today', 'var2'=>'yesterday'); $filedata = array( 'type' => 'image/png', 'data' => file_get_contents('http://xxx/tdr-images/images/mapping/dynamic/deals/spot_map') ); echo '<pre>'.postToHost ("localhost", 80, "/test3.php", $postdata, $filedata).'</pre>'; Hello, I have a directory on my site named "spanish", and I would like any webpage in that directory to be translated to spanish automatically. So is there a way to tell mod_rewrite to add the following string (below) to the beginning of the URL ONLY IF the webpage is in the directory "spanish"? String I'm trying to add to beginning of URL http://translate.google.com/translate?hl=en&sl=en&tl=es&u= So say the url was: www.optimumhealthcare.org/spanish/page.html I would want it to change that URL to: http://translate.google.com/translate?hl=en&sl=en&tl=es&u=www.optimumhealthcare.org/spanish/page.html Any help would be greatly appreciated! Thanks This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=308956.0 Hey guys. I currently have my website set up 'generating' php pages, rather than simply getting data off the database. Which is silly. I have no rectified that issue but end up with ugly urls such as http://www.worldwidelighthouses.com/Lighthouses/English-Lighthouses/Trinity-House-Owned/Lighthouse.php?Lighthouses=Beachy-Head Whats the best way to translate that into http://www.worldwidelighthouses.com/Lighthouses/English-Lighthouses/Trinity-House-Owned/Beachy-Head Im hopeless with apaches mod_rewrite... Many many thanks in advance. Danny Hello. I've set up pagination for my results. I do this with a class. I also have pretty urls with mod_rewrite. I'm wondering how to echo the urls for the paginated data. Currently I have this below for the links. this is in my page.class.php file. I call for it with an include. $links .= ' ' . $prefix . '<a href="' . $this->php_self . '?' . $this->append . '&page=' . $i . '">' . $i . '</a>' . $suffix . ' '; This echos out a link like this which is in my tag page. /index.php?menu=tags&tag=action&page=2 My mod_rewrite works and looks like this /tags/action/page/2 Question is.. How do I change the url in my first code to work with my mod_rewrite? I'm using this class through my whole site so I don't want to just add /tags/ to the first code.. Any ideas? A few questions about mod_rewrites... 1.) If I want to determine if the URL ends with either "list" or "gallery", and then take appropriate action, does the code below look correct?
RewriteRule shop/(.+)/([list|gallery])$ shop/catalog.php?category=$1&view=2 [L]
2.) Is it bad to use mod_rewrites to determine how your website branches? For example...
RewriteRule shop/music/(.*)$ go somewhere [L] RewriteRule shop/movies/(.*)$ go somewhere else [L] RewriteRule shop/books/(.*)$ go yet somewhere else [L]
This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=309061.0 I am trying to handle 404 errors to mainly pdf files that used to reside in a different directory but have now moved permanantly to a new directory. I have tired many variations for the rewrite and none have worked or even given me errors to make me think I am kind on the right track.
This is the line I have tried using
RewriteRule ^/files/starter-manuals(.*) /admin_files/PDF$1 [R=301,L]This is an example of a url that should be redirected http://remotelystart...nuals/RS625.pdf Here is a copy of the whole htaccess just in case something else if mking it not work. RewriteEngine On RewriteCond %{HTTP_HOST} ^www.remotelystartedmn.com$ [NC] RewriteRule ^(.*)$ http://remotelystartedmn.com/$1 [R=301,L] RewriteCond %{QUERY_STRING} ^product_id=(.*)$ RewriteRule . %{REQUEST_URI}?product-id=%1 [R=301,L] RewriteBase / RewriteCond %{HTTP:Cookie} devicePixelRatio [NC] RewriteRule \.(?:jpe?g|gif|png|bmp)$ /retinaimages.php [NC,L] RewriteRule ^/files/starter-manuals/(.*) /admin_files/PDF/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-s RewriteRule ^(.*)\.[\d]+\.(css|js)$ $1.$2 [L] ErrorDocument 404 /404.php # ---------------------------------------------------------------------- # Expires headers (for better cache control) # ---------------------------------------------------------------------- # # These are pretty far-future expires headers # They assume you control versioning with cachebusting query params like: # <script src="application.js?20100608"> # Additionally, consider that outdated proxies may miscache # # www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ # # If you don`t use filenames to version, lower the css and js to something like "access plus 1 week" # <IfModule mod_expires.c> ExpiresActive on # Perhaps better to whitelist expires rules? Perhaps. ExpiresDefault "access plus 1 month" # cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5) ExpiresByType text/cache-manifest "access plus 0 seconds" # Your document html ExpiresByType text/html "access plus 0 seconds" # Data ExpiresByType text/xml "access plus 0 seconds" ExpiresByType application/xml "access plus 0 seconds" ExpiresByType application/json "access plus 0 seconds" # RSS feed ExpiresByType application/rss+xml "access plus 1 hour" # Favicon (cannot be renamed) ExpiresByType image/x-icon "access plus 1 week" # Media: images, video, audio ExpiresByType image/gif "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType image/jpg "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" ExpiresByType video/ogg "access plus 1 month" ExpiresByType audio/ogg "access plus 1 month" ExpiresByType video/mp4 "access plus 1 month" ExpiresByType video/webm "access plus 1 month" # HTC files (css3pie) ExpiresByType text/x-component "access plus 1 month" # Webfonts ExpiresByType font/truetype "access plus 1 month" ExpiresByType font/opentype "access plus 1 month" ExpiresByType application/x-font-woff "access plus 1 month" ExpiresByType image/svg+xml "access plus 1 month" ExpiresByType application/vnd.ms-fontobject "access plus 1 month" # CSS and JavaScript ExpiresByType text/css "access plus 1 month" ExpiresByType application/javascript "access plus 1 month" ExpiresByType text/javascript "access plus 1 month" <IfModule mod_headers.c> Header append Cache-Control "public" </IfModule> </IfModule> AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascriptI have also tried putting the line in question above the RewriteBase, putting an absolute url for both directories and removed/moved slashes before/after just about everything but nothing has worked. Any insight is appreciated! This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=357809.0 Hi, I have This Url After Click Link For Access and download file . Code: [Select] index.php?module=Files&action=show&id=default&download=yes&id=$_REQUEST[id] I set my mod_rewrite to : Code: [Select] RewriteRule ^files/(.*)/?$ index.php?module=Files&action=show&id=default&download=yes&id=$1in download page i have this for accept & download file : Code: [Select] if ($_REQUEST[download] == 'yes') { //check and create MYSQL Result echo " <meta http-equiv=\"refresh\" content=\"0; url=$cms[url]\">"; // $cms[url] = test.jpg } Now generate url (domain.com/files/test.jpg) but not refresh and not show file for download ( new Page)! what's problem ! thaks for any help This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=328210.0 I have recently discovered the mod_rewrite, and so now i've got rewrite settings on my server where by it will not map /series/english/myseries to index.php?q=english&series=myseries; Which is all very well and good and works nicely. However, When I am trying to load say a Javascript file inside Index.php now, or include a PHP file, I have huge problems, because it is trying to look at my 'relative' path of 'js/jquery.js' and cant find it from the pseudo directory 'series/english/myseries'. What is the best way to compensate for this problem? For the PHP includes i've started using $_SERVER['DOCUMENT_ROOT']; which seems to map files okay. But i can't do the same with JS. I dont know what to do Hello All,
I have mod_rewrited working properly but when I enabled SSL it stopped working. Please help me its really frusterating now
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L] RewriteRule ^shorter/(.*)$ shorter.php?longurl=$1 [L] RewriteRule ^([0-9a-zA-Z]{1,6})$ redirect.php?url=$1 [L] RewriteRule (.*)playlist.xml$ playlist.php [L] # Playlist RewriteRule ^(.*)/$ /index.php?page=$1 [L] RewriteRule ^(.*)/(.*)/$ /index.php?page=$1&id=$2 [L] RewriteRule ^(.*)/(.*)/(.*)/$ /index.php?page=$1&id=$2&no=$3 [L] RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ /index.php?page=$1&id=$2&no=$3&trkid=$4 [L] RewriteRule ^(.*)/(.*)/(.*)/$ /index.php?page=my_profile&code=$2&state=$3 [L]In this site redirects properly to https but it do not work with permalinks http://www.domain.com/music/ << was working fine https://www.domain.com/music/ << Now stopped I Tried RewriteRule (.*)playlist.xml$ https://%{SERVER_NAME}/playlist.php [L] # Playlist #AND Optionally RewriteRule (.*)playlist.xml$ https://www.domain.com/playlist.php [L] # PlaylistBut no success Please help This topic has been $verb->toPastTense() to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=354538.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=321843.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=356538.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=355043.0 |