appending to the beginning of a URL string using isapi 3 - isapi

Trying to take an existing URL say: domain.com/qe/info/happy/
and prepend with the following: /qe-happy/
before: domain.com/qe/info/happy/
after: new.com/info/qe-happy/
I am using asapi 3

Try using:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP:Host} ^domain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/qe/info/(.*)$
RewriteRule ^(.+)$ http://new.com/info/qe-%1 [NC,R=301,L]

Related

CakePHP controller , Url not found on server

I write a controller in CakePhp-2.9 named API to access outside.
Controller Code:
class APIController extends AppController
{
var $name = 'API';
var $cache_dir = 'img/cache';
var $cache_width = 400;
public $msgs = array();
public function beforeFilter()
{
parent::beforeFilter();
$this->Auth->allow('ecall_request','ecall_callback','testlog','ecall_request_test','ecall_callback_test');
}
public function ecall_request()
{
Cache::write("test_request".time(),$this->request->data);
if($this->request->is('post'))
{
// my code here
}
}
}
And i tested "http://localhost/dentech/api/ecall_request" on POSTMAN successfully, But when i upload it on server at https://dentech.com/api/ecall_request it does not access and gives 404 error.
htaccess code is:
<IfModule mod_rewrite.c>
RewriteEngine on
# Uncomment if you have a .well-known directory in the root folder, e.g. for the Let's Encrypt challenge
# https://tools.ietf.org/html/rfc5785
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
Updated from comments: The reason for the 404-error is that the controller name in the URL has to be in uppercase characters. Instead of
https://dentech.com/api/ecall_request
You need to use
https://dentech.com/API/ecall_request
The fact that it works on localhost but not on the server is the difference in the operating system. Windows (often used locally) is not case-sensitive, while Linux (usually the servers OS) is case-sensitive.

Symfony does not detect relative url root

In symfony 1.4 in settings.yml we are using the option:
env:
request:
param:
relative_url_root: /name-of-app
to specify which relative_url_root an app uses. So every app runs under a different relative_url_root.
The problem is that symfony 1.4 routing does not detect this relative url root. So for example if we have the following route:
route_name:
url: /some-module/some-action
param: { module: somemodule, action: someaction }
And we try to access http://myproject.local/name-of-app/some-module/some-action symfony tries to search for a route name which matches name-of-app/some-module/some-action instead of /some-module/some-action.
Also symfony now tries link to images using this relative_url_root, therefore images are not found anymore. Because images are only reachable via http://project.local/img/.. instead of http://project.local/name-of-app/img
What is the best way to solve this?
Should I remove a '/' somewhere?
Should I use RewriteBase somehow in htaccess?
Should I strip 'name-of-app' in the REQUEST_URI using htaccess?
Prefix every routing url with name-of-app/?
Should I in someway tell apache that /name-of-app is some kind of path or prefix? Note that in our production environment we are not able to create virtual hosts so we have to solve this using .htaccess or symfony itself.
A very different solution.
I'm not sure if the relative_url_root is what you're really after. As the documentation states:
relative_url_root
The relative_url_root option defines the part of the URL before the front controller. Most of the time, this is automatically detected by the framework and does not need to be changed.
So it is part of the URL before index.php or frontend_dev.php, etc.
What you could do, in my opinion, is to write your own Routing class which will extend the sfPatternRouting and have it remove the prefix part of your URLs before trying to match any route. Then use this class for routing in factories.yml.
EDIT: I somehow missed the fact that you operate between different applications.
In general the relative_url_root is definitely not a good idea to separate calls to different apps. The best way, in my opinion, would be to use separate front controllers and Virtual Hosts to have different subdomains. Unfortunately you say you cannot go for this option.
You could then go for either of the solutions:
Fiddle with .htaccess and have it redirect your calls to a proper front controller: myurl.com/path-to-app1/something will call app1.php/something and myurl.com/path-to-app2/something will call app2.php/something.
Change the index.php file. Have it catch the first part of URL (path-to-app/) and based on it's value load the configuration for the proper app (e.g. $configuration = ProjectConfiguration::getApplicationConfiguration('app2', 'prod', false);)
You would then have to change your routes to take into consideration that there is this first part of URL (e.g. have all your routes start with a :path-to-action variable which will be passed to functions generating URLs), or use a parameter defined in config:
.
In apps/app1/config/app.yml
path_to_app: app1
In apps/app1/config/routing.yml
route1:
url: <?php echo sfConfig::get('app_path_to_app') ?>/something
...
Fix for the routing:
I changed my .htaccess as follows.
RewriteCond %{HTTP_HOST} myproject.local
RewriteCond %{THE_REQUEST} /name-of-app* [NC]
RewriteRule ^(.*)$ dispatcher.php/$1 [QSA,L]
By using this rewrite rule symfony seems to recognize that /name-of-app is a prefix in the routing and somehow matches this on the relative_url_root. Now when I var_dump the sfRoute object in the controller I get the following.
object(sfRoute)[33]
protected 'isBound' => boolean true
protected 'context' =>
array (size=7)
'path_info' => string 'some-module/some-action' (length=10)
'prefix' => string '/name-of-appp' (length=8)
'method' => string 'GET' (length=3)
'format' => null
'host' => string 'myproject.local' (length=20)
'is_secure' => boolean true
'request_uri' => string 'https://myproject.local/name-of-app/some-module/some-action' (length=47)
Note that I did not change the routing rules as Michal suggested. Also I believe my approach with the relative_url_root is not really that strange as Symfony understands it.
Fix for direct file access:
In order to redirect a request like https://myproject.local/name-of-app/some/path/to/a/file.ext to https://myproject.local/some/path/to/a/file.ext I used the following directives.
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteCond %{REQUEST_URI} ^/name-of-app
RewriteRule ^name-of-app/(.*)$ https://myproject.local/$1 [L]

Routes and Path in CakePHP

i am currently dvelpping a website for a friend and i have a strange issue.
Let me first say i am rather a non experienced developper and I cant seem to find a solution:
I've localized my websites in different languages you can watch it here:
http://parfum-poudre.fr/en (in English) it works fine
but if you go to http://parfum-poudre.fr/en/ the paths are messed up and some pics don't appear...
for example there is a professional sapce on this website but then if you go back on the public space i have the same issue...
anyone ha s anything to say about that ?
Thanks
Have added your images, scripts and styles using normal HTML tag in layout file?
This can be one issue.
You can add images,scripts and styles to your layout file using
<?php
echo $this -> Html -> css('style');
echo $this -> Html -> script('jquery');
echo $this -> fetch('css');
echo $this -> fetch('script');
?>
<?php echo $this->Html->image('logo2.png', array('url' => '/ProjectName/','alt'=>'Logo')); ?>
Add this to your app_helper.php
class AppHelper extends Helper {
function url($url = null, $full = false) {
$routerUrl = Router::url($url, $full);
if (!preg_match('/\\.(rss|html|js|css|jpeg|jpg|gif|png|xml?)$/', strtolower($routerUrl)) && substr($routerUrl, -1) != '/') {
$routerUrl .= '/';
}
return $routerUrl;
}
}
The AppHelper stuff goes in the app_helper.php file located in HTDOCS/PROJECT/APP folder (APP ROOT). If the file doesn't exits, create one.
And edit your .htaccess to
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]
The .htaccess code goes in the .htaccess file in HTDOCS/PROJECT/APP/WEBROOT folder (APP ROOT/WEBROOT). Just replace the original contents and make sure you change domain.com to whatever your domain is.

CakePHP plus sign in named parameter decode as space

This is problem with value of named parameter when the value contain character + (plus).
The url is http://localhost/kidwatcher/messages/sentbox/number:+6581235251237
When I try to var_dump the named paramater (which in this case is number), character + becomes a space.
string(14) " 6581235251237"
Character + is %2B, the result is same when I change the url:
http://localhost/kidwatcher/messages/sentbox/number:%2B6581235251237
string(14) " 6581235251237"
But when I use url query string, it works.
http://localhost/kidwatcher/messages/sentbox?number=%2B6581235251237
string(14) "+6581235251237"
What's wrong with named parameter?
Okay, now i have solution for this problem.
In folder app/webroot
Edit .htaccess to
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L,B]
</IfModule>

cakephp redirection error after login return HTTP/1.1 302 in the logs

I have implemented cakephp redirect() function on successfull login into my application .
But the redirection is not working for some reasons and it is instead getting redirected to the same url , while in the APACHE logs , I can see HTTP 302 response for that redirected URL .
My code is something as under :
if(isset($_REQUEST['submit']) && $_REQUEST['submit']=='Log In')
{
/*Entire validation logic goes here*/
if(isset($famUserInfo['user_type']) && $famUserInfo['user_type'] == USER_TYPE_ADVERTISER)
{
$redirectTo = !empty($returnto)?$returnto:'/homepageadv?login=1';
}
else if(isset($adminUserInfo['user_type']) && $adminUserInfo['user_type'] == USER_TYPE_ADMIN)
{
/* My control flow comes till here successfully */
$this->redirect("/opstool/zoneprobabilityindex");
die;
}
else
{
$redirectTo = !empty($returnto)?$returnto:'/homepage?login=1';
}
$this->redirect($redirectTo);
die;
}
When I check in the APACHE logs , I noticed like these :
127.0.0.1 - - [14/Oct/2011:19:24:34 +0530] "POST /login?returnto= HTTP/1.1" 302 5
127.0.0.1 - - [14/Oct/2011:19:24:34 +0530] "GET /opstool/zoneprobabilityindex HTTP/1.1" 302 12
127.0.0.1 - - [14/Oct/2011:19:24:34 +0530] "GET /login?returnto= HTTP/1.1" 200 6057
http://localhost:9001/login?returnto= is my login page url and this where it's returning to.
My .htaccess contents is inside /app folder and is as follows :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Please help. I am struck on this.

Resources