I am using cakephp v2.3.8 and struggle a bit with the routing.
The old url is www.domain.com/properties.aspx?prop=1999
I want to route this to the properties controller with id = 1999 so my url will look like:
www.domain.com/properties/view/1999
In my routes.php i strip the .aspx out of the url but struggle with this last bit.
Router::parseExtensions('htm','html','aspx');
This is how close I am:
Router::connect('/properties', array('controller' => 'properties', 'action' => 'view', ??? '));
This is the view function in the PropertiesController.php
public function view($id = null) {
if (!$this->Property->exists($id)) {
throw new NotFoundException(__('Sorry, we couldn\'t find what you were looking for...'));
}
$options = array('conditions' => array('Property.' . $this->Property->primaryKey => $id));
$propData = $this->Property->find('first', $options);
$this->set('property', $propData);
}
This works perfect within the website, but not for those as mentioned, they are redirected to www.domain.com/properties
This is my .htaccess file in the public_html folder.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
Thanks for looking into this.
File structure:
.htaccess [1]
/app/.htaccess [2]
/lib/Cake/
/public_html/.htaccess [3]
/plugins/
/vendors/
[1]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
[2]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
[3]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
/public_html/index.php
if (!defined('ROOT')) {
define('ROOT', DS.'home'.DS. 'user');
}
/**
* The actual directory name for the "app".
*
*/
if (!defined('APP_DIR')) {
define('APP_DIR', 'app');
}