Htaccess ReWrite mod error
Can anybody help me find out solution?
While using this rewrite rule
RewriteRule ^([a-zA-Z0-9_\s]+)/([a-zA-Z0-9_\s]+)/([a-zA-Z0-9._,()&/\s]+)$ loader.php?option=$1&page=$2&storeid=$3 [L]
i got error in server like
RewriteRule: cannot compile regular expression '^([a-zA-Z0-9_\\s]+)/([a-zA-Z0-9_\\s]+)/([a-zA-Z0-9_,()&'/-\\s]+)$'
Comments
([a-zA-Z0-9._,()&/\s]+) anyproblem on this part? i thought / is special character and need to escaped with '\/'??
^([a-zA-Z0-9_\s]+)/([0-9]+)/([0-9]+)$ loader.php?option=$1&page=$2&storeid=$3 [L]
which means for example if you have a gallery.php in /controller folder and there is a loader function such as public function loader($option,$page,$store)
you can set the routing in route.php as
$route['([a-z]+)/([a-z]+)\-(:num)/([a-z]+)\-(:num)']="gallery/loader/$1/$3/$5";
1. you are using fuel cms??
2. you want to redirect http://localhost/ft/photogallery/galleryimage/galleryid-71/galcategoryid-12 to loader.php?option=galleryimage&page=71&storeid=12??
3. where you put your loader.php??
2.
a). http://localhost/furniture_n/photogallery
b).photogallery_office furniture: http://localhost/furniture_n/photogallery/type-picture/galcategoryid-12
c) photogallery_office furniture-executive chair: http://localhost/furniture_n/photogallery/galleryimage/galleryid-71/galcategoryid-12
d) photogallery_office furniture-executive chair-chair model:http://localhost/furniture_n/images/galleryimage/20131206075747.jpg
3. loader file is in root directoy
you can put the .htaccess like below to redirect a),b),c) above to loader.php by
Options +FollowSymLinks
RewriteEngine On
RewriteBase /furniture_n/
Order Deny,Allow
Deny From All
# Allow option a through
RewriteRule ^photogallery/?$ loader.php [L,NC]
# Allow option b through
RewriteRule ^photogallery/([a-zA-Z0-9]+)\-([a-zA-Z0-9]+)/([a-zA-Z0-9]+)\-([0-9]+)/?$ loader.php?option=$2&storeid=$4 [L,QSA,NC]
# Allow option c through
RewriteRule ^photogallery/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)\-([0-9]+)/([a-zA-Z0-9]+)\-([0-9]+)/?$ loader.php?option=$1&page=$3&storeid=$5 [L,QSA,NC]
Options -Indexes
on loader.php try
print_r($_GET);exit;
# Allow option a through
RewriteRule ^photogallery/?$ loader.php [L,NC]
# Allow option b through
RewriteRule ^photogallery/([a-zA-Z0-9]+)\-([a-zA-Z0-9]+)/([a-zA-Z0-9]+)\-([0-9]+)/?$ loader.php?option=$2&storeid=$4 [L,QSA,NC]
# Allow option c through
RewriteRule ^photogallery/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)\-([0-9]+)/([a-zA-Z0-9]+)\-([0-9]+)/?$ loader.php?option=$1&page=$3&storeid=$5 [L,QSA,NC]
The error message are:
Warning: dir(modules/picture): failed to open dir: No such file or directory in /home/wwwmakal/public_html/furni/modules/kernel/class.Kernel.php on line 58
Fatal error: Call to a member function read() on a non-object in /home/wwwmakal/public_html/furni/modules/kernel/class.Kernel.php on line 59
line 58 $dir = dir("modules/".$dir_path);
line 59 while ( false !== ( $entry = $dir->read() ) )
anyway,
http://localhost/furniture_n/photogallery/type-picture/galcategoryid-12 by using the above .htaccess will pass "picture" to the loader.php , so please check under modules folder if there is a "picture" folder or rather "type-picture" folder. If there is a "type-picture" folder, use
# Allow option b through
RewriteRule ^photogallery/([a-zA-Z0-9\-]+)/([a-zA-Z0-9]+)\-([0-9]+)/?$ loader.php?option=$1&page=$3 [L,QSA,NC]
instead
a). http://localhost/furniture_n/photogallery
b).photogallery_office furniture: http://localhost/furniture_n/photogallery/type-picture/galcategoryid-12
c) photogallery_office furniture-executive chair: http://localhost/furniture_n/photogallery/galleryimage/galleryid-71/galcategoryid-12
d) photogallery_office furniture-executive chair-chair model:http://localhost/furniture_n/images/galleryimage/20131206075747.jpg
currently only option b fail? the rest working?
i take a look of the script. The flow of the script follows by
1. reach loader.php
2. loader.php then load a group of script
3. loader.php first check url for option parameter if there is then redirect to "option" folders under /modules. If options no specificied redirect to /modules/home
So rewrite rule
RewriteRule ^$ loader.php?option=home&page=view [L]
RewriteRule ^([a-zA-Z0-9_]+)/?$ loader.php?option=$1&page=view [L,QSA]
4. loader.php second check url for sub parameter if there is then redirect to folders under /modules/{option}/{sub} folder ( this isn't necessary, as i checked the folders under your modules folder, there arent any sub folder.
so you can ignore this, there isnt any need for rewrite rule for this one
5. loader.php third check url for page parameter, then redirect to /modules/{option}/{page}.php
so use
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/?$ loader.php?option=$1&page=$2 [L,QSA]
6. loader.php fourth check url for storeid parameter, the storeid requrested by this system is complex by requesting the format of "galleryid-71/galcategoryid-12/pg-3/type-video", you can observe the pattern here
in function show() in /modules/photogallery/view.php
$correctid = getid($_GET['storeid']);
$galcategorytype = $correctid['type'];
$this->galcategoryid = $correctid['galcategoryid'];
if($this->galcategoryid)
{
$galcatdetail = $this->getgalCategoryDetail();
}
$this->pg = $correctid['pg'];
in function getid() in global_functions.php
function getid($storeid)
{
//here $storeid is the getid from the url
$exp=explode('/',$storeid);
foreach($exp as $key=>$val)
{
$tempid=explode('-',$val);
$correctid[$tempid[0]]=$tempid[1] ;
}
return $correctid;
}
so
RewriteRule ^([a-zA-Z0-9_\s]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_\/\-&]+)$ loader.php?option=$1&page=$2&storeid=$3 [L,QSA]
solved the part.
if you see a lot of missing parameters error, basically because you did not provide parameters values in the url, i would suggest you use isset($_GET['pg']) something like this to handle the issue, and is good for you to define a default value for it.
complete .htaccess
Options -Indexes
RewriteBase /ft/
RewriteEngine on
RewriteRule ^$ loader.php?option=home [L]
RewriteRule ^([a-zA-Z0-9_]+)/?$ loader.php?option=$1&page=view [L,QSA]
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/?$ loader.php?option=$1&page=$2 [L,QSA]
RewriteRule ^([a-zA-Z0-9_\s]+)/([a-zA-Z0-9_]+)/([a-zA-Z0-9_\/\-&]+)$ loader.php?option=$1&page=$2&storeid=$3 [L,QSA]
Not Found
The requested URL /furni/photogallery/type-picture/galcategoryid-12 was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
one is to change the url from /furni/photogallery/type-picture/galcategoryid-12 to /furni/photogallery/view/type-picture/galcategoryid-12
second is to add in this rule RewriteRule ^([a-zA-Z0-9_\s]+)/([a-zA-Z0-9_\/\-&]+)$ loader.php?option=$1&page=view&storeid=$2 [L,QSA]
in every case you need to try to include a page parameter for your scripts.