Mapserver trouble wrapping cgi-bin/mapserv and map=mapfile.map - .htaccess

I am using Mapserver 7.0.7 (MS4W 3.2.8) and i'm having trouble wrapping cgi-bin/mapserv and map=mapfile.map
work fine in
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Leaflet/mapserver/Leaflet.map&service=WMS&request=GetMap&layers=LAT&styles=&format=image%2Fpng&transparent=true&version=1.3.0&tiled=true&width=512&height=512&crs=EPSG%3A3857&bbox=-6574807.424977722,-3443946.7464169012,-6261721.357121639,-3130860.67856082
result
using RewriteRule in .htaccess into the folder on my leafletjs web
RewriteRule ^ms(.*)$ http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Leaflet/mapserver/Leaflet.map$1
http://10.1.3.21/Leaflet/ms&service=WMS&request=GetMap&layers=LAT&styles=&format=image%2Fpng&transparent=true&version=1.3.0&tiled=true&width=512&height=512&crs=EPSG%3A3857&bbox=-6574807.424977722,-3443946.7464169012,-6261721.357121639,-3130860.67856082
result:
Not Found
The requested URL /Leaflet/ms&service=WMS&request=GetMap&layers=LAT&styles=&format=image/png&transparent=true&version=1.3.0&tiled=true&width=512&height=512&crs=EPSG:3857&bbox=-6574807.424977722,-3443946.7464169012,-6261721.357121639,-3130860.67856082 was not found on this server.
but is a working GetCapabilities request
http://localhost/Leaflet/ms&service=WMS&version=1.0.0&request=GetCapabilities
and it is replaced as =>
http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Leaflet/mapserver/Leaflet.map&service=WMS&version=1.0.0&request=GetCapabilities
result:
<!-- end of DOCTYPE declaration -->
<WMT_MS_Capabilities version="1.0.0">
<!--
MapServer version 7.0.7 (MS4W 3.2.8) OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=CAIRO SUPPORTS=SVG_SYMBOLS SUPPORTS=SVGCAIRO SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUPPORTS=THREADS SUPPORTS=GEOS SUPPORTS=POINT_Z_M INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE
-->
<Service>
<Name>GetMap</Name>
<Title>Leaflet - WMS</Title>
<OnlineResource>http://localhost/Leaflet/ms?</OnlineResource>
</Service>
...

Your rewrite rule is removing the important ? querystring character, creating an invalid request such as /Leaflet/ms&service=WMS&... but it should result as /Leaflet/ms?service=WMS... Try a rule such as:
RewriteRule ^ms?(.*)$ http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w/apps/Leaflet/mapserver/Leaflet.map$1

Related

.htaccees redirect on long string

I wan't .htaccees to check it the url string is longer thnr 155 chars. If it is I want to redirect to an error page.
Her is a rule that does it (I think) for a 155 long query string, but I can't find a way to to this for a 155 and longer string. Also I am afraid that works only for url and not query string.
RewriteRule ^([a-zA-Z0-9]{155,})/?$ 404.php?u=$1 [QSA,L]
Why don't you try to preform the check in index file?
Here is an example:
$allowedL = 155;
$path = $SERVER['REQUEST_URI'];
if ( strlen($path) > $allowedL ) die();

Using OR in htaccess redirect

Following URL should be redirected:
abc-deut.html -> de/abc
abc-eng.html -> en/abc
Where deut = de
And eng = en
I am looking for something like:
RewriteRule ^abc-(deut|eng).html (de|en)/abc [R=301,L]
Does this work with htaccess?
You can use this rule:
RewriteRule ^([\w-]+)-(en|de).*\.html$ /$2/$1 [R=301,L,NE,NC]

htaccess RewriteRule URL's

I use htaccess to rewrite my URL's so here is what I have:
RewriteRule ^([^-]+),([a-z0-9._.-]+),([^-]+) index.php?go=$1&lang=$2 [L]
and code PHP:
function rewrite_seo($id, $title, $langs) {
global $core;
if($core->getSettings('seof')) {
$result = $id.','.$langs.','.changeSigns($title).'';
} else $result = '?go='.$id.'&lang='.$langs;
return $result;
}
My URLs look like:
http://localhost/script/12,en,home
but want to look like this:
http://localhost/script/en/home,12
how to modify this code?
localhost/script/12,en,home TO
localhost/script/en/home,12
Did u try to modify line 4?
Put that:
$result = $langs.'/'.changeSigns($title).','.$id;
Please take a look to PHP.net webpage http://php.net/manual/de/internals2.opcodes.concat.php
You have to change the links written in PHP as pointed out in the previous answer :
$result = $langs.'/'.changeSigns($title).','.$id;
And then change the matching rule in your htaccess :
RewriteRule ^([a-z0-9._.-]+)\/([^-]+),([^-]+) index.php?go=$2&lang=$1 [L]
Even better, you can make more specific capture regex, so it would be easier to read and understand :
RewriteRule ^([a-z]+)\/([0-9]+),([^-]+) index.php?go=$2&lang=$1 [L]

Rewrite rule with redirect in php

I seem to have problem with an .htaccess rewriterule.
What I want to do is a dispatcher of this form:
[website]/[parameter1-text]/[parameter2-text]
I have in my .htaccess the following:
RewriteRule ^(.*)/(.*)$ dispatcher.php?s1=$1&s2=$2
So far so good. But s1 and s2 are some variables that need to be matched in a database (mysql) and return the true variables that feed the script view.php in the following format:
view.php?category=[s1]&subcategory=[s2]&objects=5
How can I redirect this properly using header("Location: /view.php[...]"); and having the url unchanged (for example: http://example.com/CARS/BLUE http://example.com/SLIPPERS/RED/ )
First of all fix some minor issues with your .htaccess:
RewriteRule ^([^/]+)/([^/]*)/?$ dispatcher.php?s1=$1&s2=$2 [L,QSA]
Now inside dispatcher.php do your Mysql stuff and fetch values of s1 and s2 from database. Once you're done and want to internally forward your request to: view.php?category=[s1]&subcategory=[s2]&objects=5 have this type of PHP code:
$_GET['category'] = $value-of-s1-from-DB;
$_REQUEST['category'] = $_GET['category'];
$_GET['subcategory'] = $value-of-s2-from-DB;
$_REQUEST['subcategory'] = $_GET['subcategory'];
$_GET['objects'] = '5';
$_REQUEST['objects'] = $_GET['objects'];
// now include view.php
// all your parameters are available in view.php in $_GET array
require_once("view.php");

How can I go back to showing the content of /index.php?

Here's part of my .htaccess file:
.htaccess:
RewriteRule ^([a-z0-9A-Z_-]+)$ /article/index.php?title=$1 [L]
But the problem is that when title is empty it doesn't show me the content of http://www.domain.com/index.php. I can't even link to http://www.domain.com/ anymore without throwing the error.
PHP: http://www.domain.com/article/index.php
<?php
if(!empty($_GET['title']))
{
$a = mysql_query("SELECT * FROM `articles` WHERE `title` = '".mysql_real_escape_string($_GET['title'])."'");
}
else
{
$a = mysql_query("SELECT * FROM `articles` WHERE `id` = '".mysql_real_escape_string($_GET['id'])."'");
}
$b = mysql_fetch_assoc($a) or mysql_error();
?>
You pretty much have 2 choices:
1. Use this rule: If home page is hit, then title parameter will be empty (so you have to handle this moment somehow -- adjust your PHP code accordingly).
RewriteRule ^([a-z0-9A-Z_-]*)$ /article/index.php?title=$1 [QSA,L]
2. Use specific rule for home page/website root hit (add it before your current rule):
RewriteRule ^$ /article/index.php?title=home [QSA,L]
The title=home means it's a hit for website root (you can change home to whatever you want).

Resources