I used CI's routes and have the following entry in config/routes.php
if($subdomain == 'debug')
{
$route['debug/(:any)'] = "admin/debug/$1";
}
elseif($subdomain == 'dev')
{
$route['models/(:any)'] = "v2/dev/models/$1";
}
If I were to browse to
dev.mydomain.com/models/test/
everything works fine and I get the correct output.
However, I were to browse to
dev.mydomain.com/models/test/trip_id/9091
I will get a 404 Error page.
Only way to make it to work is to use the following route entry.
$route['models/(:any)/(:any)/(:any)'] = "v2/dev/models/$1/$2/$3";
What really confuses me further is that it works if I were to browse to
debug.mydomain.com/debug/test/trip_id/9091
What am I missing here as the route entries looks similar but will only work on the first subdomain (debug.mydomain.com) but not on the latter (dev.mydomain.com)
This is the content of my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Any help is greatly appreciated.
$route['models/(:any)'] = "v2/dev/models/$1";
Check the route path if you are calling the controller from the folder
it should be yourfolder/controller/method_name/$1
Related
The problem description is very specific, but i have no idea about its source
The project uses Laravel 5.1
I have a project copy on my computer and remote server. Local server is configured to remove /public from URL with VirtualHost. On remote server, project is located in subdirectory. E.g. /project. To get rid of public, there is an alias in httpd.conf and line RewriteBase /project in /project/public/.htaccess
The problem appears when using Laravel's pagination mechanism:
There are links to pages in the page with navigation. On local machine everything is OK, but on remote server clicking on link with URL like http://<server_ip>/project/navigationPage?page=N causes redirect to http://<server_ip>/navigationPage?page=N. Of course, 404 error appears.
What is the problem and how to fix it?
Full .htaccess in /project/public:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /project
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Ok, problem was in slash that was added to links by paginator. Link was looking like http:///project/navigationPage/?page=N, but must look like http:///project/navigationPage?page=N (without slash). Bug fixed by editing AbstractPaginator's url function:
public function url($page)
{
if ($page <= 0) {
$page = 1;
}
$parameters = [$this->pageName => $page];
if (count($this->query) > 0) {
$parameters = array_merge($this->query, $parameters);
}
return rtrim($this->path, '/').'?'
.urldecode(http_build_query($parameters, null, '&'))
.$this->buildFragment();
}
I'm trying to route an old URL like
...file.php?a=login
to a CakePHP request like
/somecontrollerA/login/
but it seems that routing only supports the URL without parameters, and mod_rewrite does not work since CakePHP uses $_SERVER['REQUEST_URI'] and not $_SERVER['REDIRECT_URL'].
Is it possible do something like this?
I finnaly found a solution, not really good but worked for the purpose.
open /webroot/index.php
put the following code at start of file (thanks to AD7six)
if (isset($_SERVER['REDIRECT_URL'])) {
$_SERVER['REQUEST_URI'] = preg_replace("/^(.*?)\/webroot/", "$1", $_SERVER['REDIRECT_URL']);
}
then .htaccess file inside /webroot/ (lines 3 and 4)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^a=login$ [NC]
RewriteRule ^(.*)myfile\.php$ controllerA/login [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
now cake recognizes myproject/myfile.php?a=login as /controllerA/login
I have my query string to include my pages, in my homepage like you see below and it is working fine, Im including my pages fine.
But something wrong is happening and Im not finding how I can solve this.
I will try to expain my isse with an example: I have a folder "teachers" inside I have two pdf documents and a page "documents.php".
To acess this documents page, Im acessing: "htp://localhost/website/teachers/documents", and it is working fine.
But If I acess "htp://localhost/website/teachers/", Im able to acess my pdf documents and my page as you see in my image below.
But I dont want this, I want that If some user tries to acess "htp://localhost/website/teachers/", I want to include my 404 file (require_once('inc/404.php');)
My query string:
#$url = $_GET['url'];
$url = explode('/', $url);
$url[0] = ($url[0] == NULL ? 'index' : $url[0]);
if(file_exists('inc/'.$url[0].'.php')){
require_once('inc/'.$url[0].'.php');
}
elseif(file_exists($url[0].'/'.$url[1].'/'.$url[2].'.php')){
require_once($url[0].'/'.$url[1].'/'.$url[2].'.php');
}
elseif(#file_exists($url[0].'/'.$url[1].'.php')){
require_once($url[0].'/'.$url[1].'.php');
}
else{
require_once('inc/404.php');
}
Do you see what Im doing wrong to not be having the result I want?
My htaccess file:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1
There is an easier solution.
Add this line to the beginning of your .htaccess file:
Options -Indexes
This way, you won't be able to see the folder contents.
EDIT: htaccess rule solution (which is in website folder)
ErrorDocument 404 /website/inc/404.php
RewriteEngine On
RewriteBase /website/
RewriteRule ^teachers/$ - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L]
Hi I Have to create the URL something like "http://www.contract.com/user/profileview/index/MQ==" to "http://www.contract.com/profile/india/MQ==". We have tried the masking with codeignitor and succeeded. But coming to the Zend it is throwing the error "Invalid controller specified (india)".
We have rewrite the htaccess rules to Mask the URL in codeignitor. Same is applied here, but it is not working here. My htaccess code is
#php_value magic_quotes_gpc off
RewriteEngine on
Options -Indexes
Options FollowSymlinks
RewriteEngine On
RewriteBase /
#Admin
RewriteRule ^admin(.*)$ public_mvc/admin.php [L]
#RewriteRule ^profile/(.*)/(.*)/(.*)(/|)$ user/profileview/index/$2 [L,NC]
RewriteRule ^profile/(.*)/(.*)/(.*)(/|)$ user/profileview/index/$2 [L,NC]
#RewriteRule ^profile/(.*)/(.*)/(.*)/?$ user/profileview/index/$2 [L,NC,QSA]
# Also Tried Ones. Start
#RewriteRule ^profile/(.*)/(.*)/(.*)/$ /user/profileview/index/$1 [NC,L]
#RewriteRule ^profile/(.*)/(.*)/(.*)/?$ /user/profileview/index/$2 [NC,L]
#RewriteRule ^profile/(.*)/(.*)/(.*) /user/profileview/index/$2 [NC]
#RewriteRule ^/profile/(.*)/(.*)/(.*)/?$ /user/profileview/index/$2 [QSA]
# Also Tried Ones. End
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ public_mvc/index.php
Rewriterule ^$ /home [r=301,nc]
What is the wrong with this? We have tried so many types options. But all went in vain. You can see all those different tries in the code. Please help me this.
Thanks in advance.
"http://www.contract.com/profile/india/MQ=="
above url can be rewriter in htaccess
method 1;
RewriteRule ^profile/(.*)$ redirectedUrl.php [NC,L]
redirectedUrl.php as page, it should be placed in the root directory, it cant shows an error, regards changing the url in htaccess!!!
method 2;
handling on bootstapper.php for redirect into some controller with another action for using
Zend_Controller_Router_Route_Regex
Thanks for the Support. I have achieved the goal in some other way. We have changed the ZEND routing according to our needs. So we have Auth file(which is called in every request). This file is called in all the requests. So what I did is I checked the URL and if the URL contains the module name as 'Profile' then I have set the Module, Controller and Action name using the "setModuleName", "setControllerName", "setActionName", etc..
$ModuleName = $request->getModuleName();
$ControllderName = $request->getControllerName();
$ActionName = $request->getActionName();
/*
This condition is added to mask the URL. This is added by Ghanta Kiran on 27-Dec-2013. Start
Example : (From) http://www.contractskills.com/profile/india/username/id ==> (To) http://www.contractskills.com/user/profileview/index/id
*/
if($ModuleName == 'profile')
{
$paramId = $request->getParam('id'); // This is to get the User Id from the URL, to fetch the user profile details.
$request->setModuleName('user');
$request->setControllerName('profileview');
$request->setActionName('index');
$request->setParam('id',$paramId);
}
So what it will do is, If the URL Contains the 'Profile' in it, it will set the Module, Controller, Actions explicitly. I have done so many changes to the .htaccess, but ultimately all those efforts went wild.
I am trying to get url from:
192.168.0.1/movie-page.php?id=123
to:
192.168.0.1/movie/movie-name
or even (for now):
192.168.0.1/movie/123
I've simplified it by using this url (to get something working):
192.168.0.1/pet_care_info_07_07_2008.php TO 192.168.0.1/pet-care/
my .htaccess file:
RewriteEngine On
RewriteRule ^pet-care/?$ pet_care_info_07_07_2008.php [NC,L]
What am I doing wrong? I've tried many combinations but no luck and my patience is running out...
I am running this on my local NAS which should have mod_rewrite enabled by default. I have tested .htaccess by entering random string in .htaccess file and opening the page, I got 404 error. I assume this means that .htaccess is being used since the page stops functioning if the file is malformed.
If you want to rewrite:
192.168.0.1/movie-page.php?id=123 too
192.168.0.1/movie/movie-name or 192.168.0.1/movie/123
Then you would do something like, but will require you manually add a rewrite for any new route (fancy url) you want, and eventually you may want your script to create routes dynamically or have a single entry point to sanitize:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^movie/([a-zA-Z0-9-]+)$ movie-page.php?id=$1 [L]
So a better method is to route everything through the rewrite:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]
Then handle the route by splitting the $_GET['route'] with explode()
<?php
//192.168.0.1/movie/movie-name
$route = (isset($_GET['route'])?explode('/',$_GET['route']):null);
if(!empty($route)){
//example
$route[0]; //movie
$route[1]; //movie-name
}
?>
You want something like this:
RewriteRule ^movie/([0-9]*)$ /movie-page.php?id=$1 [L,R=301]
That will give the movie ID version with a numeric ID.