zend framework routing with "/" - apache

I have an encrypted parameter in ZF2 routing that has "/" in it for e.g:
http://domain.com/request/$2y$14$OmovR9wA1TnBG2fxdKuU9ORYTPGChgfyesGVxilP74**/**2F2t8eJgbNF2
On submit of this request the URL turns to
http://domain.com/request/$2y$14$OmovR9wA1TnBG2fxdKuU9ORYTPGChgfyesGVxilP74**%**2F2t8eJgbNF2
this causes a problem an apache server throws an error saying page not found. Is there a way from where i can stop converting the "/" to "%" in the parameter field. My .htaccess file is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
EDIT
Route code:
'exampleroute' => array(
'type' => 'segment',
'options' => array(
'route' => '/exampleroute/[:regexparameter]',
'constraints' => array(
'regexparameter' => '[$.a-zA-z0-9_-]*',
),
'defaults' => array(
'__NAMESPACE__' => 'Mynamespace\Controller',
'controller' => 'exampleroute',
'action' => 'example',
),
),
),

I had to add "%2F" => "/" in Zend\Mvc\Router\Http\Segment File in ZF2 library. Now its working fine

Related

Extra slash in urlManager rules

I'm trying to map services/v2/ to servicesV2.
I tried:
'services/v2' => 'servicesV2',
And I tried:
'services/v2/' => 'servicesV2/',
And:
'services/v2/<action:\w+>' => 'servicesV2/<action:\w+>',
And I got an error:
The system is unable to find the requested action "v2".
Did you put it on the begin of the array?
'rules' => array(
'services/v2' => 'servicesV2',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),

SEO friendly url in yii 1.1

i want only SanphamController to have from this:
mySite/sanpham/chitiet/slug/nuoc-hoa-phap-vuiton.html
to
mySite/nuoc-hoa-phap-vuiton.html
i have dealed it but all other Controller (CartController,etc,..) in my site not run anymore, it think the controller is an item in SanPhamController.
This is my code
.htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
In main/config.php:
'urlManager' => array(
'rules' => array(
'/'=>'site/index',
'<view:(gioi-thieu|huong-dan|hinh-thuc-thanh-toan|dieu-khoan-dich-vu|chinh-sach-dich-vu)>' => 'site/page',
'<action:(lienhe|thanhtoan|dangnhap|dangky|dangxuat)>' => 'site/<action>',
'danh-muc/<slug:.*>'=>'sanpham/danhmuc',
'thuong-hieu/<slug:.*>'=>'sanpham/thuonghieu',
'tim-kiem/<slug:.*>'=>'sanpham/timkiem',
'<slug:.*>' => 'sanpham/chitiet',
'<controller:\w+>/<id:\d+>' => '<controller>/chitiet',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
'urlFormat' => 'path',
'urlSuffix' => '.html',
'showScriptName' => false,
),
Simply add this rule at the top of url manager array:
"nuoc-hoa-phap-vuiton"=>"sanpham/chitiet/slug/nuoc-hoa-phap-vuiton"

How to remove trailing additional slash yii

When using the
Yii::app()->createUrl('/page/');
it is additing additional trailing slash to the url LIKE http://www.sitename// AND http://www.sitename//page
That I need to exclude two slashes, Application url manager is as follow,
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'urlSuffix' => '/',
'rules' => array(
'site/news_letter_unsubsubscribe/<id:\w+>' => 'site/news_letter_unsubsubscribe',
'page/<id:[\w\-]+>' => 'page/index/',
'site/blog_detail/<id:[\w\-]+>' => 'site/blog_detail',
'location/<id:[\w\-]+>' => 'location/index',
'auth/partner_detail/<id:[\w\-]+>' => 'auth/partner_detail',
//'tour/tour_detail/<id:\w+>/<date:\w+>'=>'tour/tour_detail',
'activity/activity_detail/<id:[\w\-]+>' => 'activity/activity_detail',
'activity/compare_detail/<id:[\w\-]+>' => 'activity/compare_detail',
'tour/tour_detail/<id:[\w\-]+>' => 'tour/tour_detail',
'tour/compare_detail/<id:[\w\-]+>' => 'tour/compare_detail',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'auth/reset_password/<id:\w+>' => 'auth/reset_password',
'site/linkedin_login/<id:\w+>' => 'site/linkedin_login',
),
)
.htaccess rules
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
In Yii2 your code is wrong. You are reading doc! Example:
echo \Yii::$app->urlManager->createUrl('page');
I could sort this issue removing the suffix slash from request base url
Thanks

How do I handle a form in a Sinatra app deployed to a sub-URI?

Possibly a newbie question here. I'm trying to deploy a Sinatra application via Passenger and Apache. The application works perfectly when deployed at the VirtualHost root, but fails to correctly handle a form post when I try to deploy it to a sub-URI.
A very simplified version of the app follows:
test-app.rb:
require 'sinatra/base'
require 'haml'
class TestApp < Sinatra::Base
get '/' do
haml :ask
end
post '/submit' do
if params[:test_string].nil? || params[:test_string].empty?
redirect '/'
end
#test_string = params[:test_string]
haml :result
end
end
layout.haml:
!!!
%html
%head
%title Test App
%body
= yield
ask.haml:
%form{:action => '/submit', :method => 'post'}
%legend
Get a string
%p
%label{:for => ''} Please enter a string:
%input{:type => 'textbox', :name => 'test_string', :id => 'test_string'}
%p
%input{:type => 'submit', :value => 'Submit >>>'}
result.haml:
%p== Here's your string: #{ #test_string }
What seems to be occurring is that the form POST isn't going to the correct URI -- it's seems to be ignoring the sub-URI config, and going to the VirtualHost root where, of course, there's no code to handle the route. I've checked and rechecked the Apache configuration, and that doesn't seem to be the problem.
<VirtualHost *:80>
ServerName my.domain.com
DocumentRoot /var/websites/home
<Directory /var/websites/home>
Allow from all
Options -MultiViews
</Directory>
Alias /test-app /var/websites/test-app/public
<Location /test-app>
PassengerBaseURI /test-app
PassengerAppRoot /var/websites/test-app
</Location>
<Directory /var/websites/test-app/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Is there any way (other than hardcoding the form) to ensure that the form posts to the sub-URI, where my application can handle it, instead of posting to the VirtualHost root?
Not sure this is the best way of handling this, but I worked around the problem by using Sinatra's url helper in ask.haml:
%form{:action => "#{ url('/submit') }", :method => 'post'}
%legend
Get a string
%p
%label{:for => ''} Please enter a string:
%input{:type => 'textbox', :name => 'test_string', :id => 'test_string'}
%p
%input{:type => 'submit', :value => 'Submit >>>'}
By doing that my form posted to the application's sub-URI rather than to the VirtualHost root.

URL management using Yii

I have url: /profile/profileBase/index where "profile" is module, "profileBase" is controller and "index" is action.
I want to url manager would accept route like: /profile/read/index
where "read" could be alias of controller.
Is there any way to do this using url manager rules?
Thanks
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'profile/read/index '=>'profile/profileBase/index'
),
),
You should simply add the following rule in urlManager config :
'profile/read/index'=>'profile/profileBase/index',