Mod rewrite mod_rewrite用于向symfony项目添加尾部斜杠
目前,myMod rewrite mod_rewrite用于向symfony项目添加尾部斜杠,mod-rewrite,symfony-1.4,Mod Rewrite,Symfony 1.4,目前,myrouting.yml中的所有URL都设置为 fooRoute: url: /foo/ params: { module:foo, action: index} 目前,用户可以通过访问example.com/foo/访问foo/index操作。我想在soexample.com/foo指向同一页面时添加一条重写规则 我当前拥有的重写规则: RewriteEngine On RewriteRule ^(.*)/$ /$1/ [R=301,L] 似乎没有任何效果。试试: Re
routing.yml
中的所有URL都设置为
fooRoute:
url: /foo/
params: { module:foo, action: index}
目前,用户可以通过访问example.com/foo/
访问foo/index操作。我想在soexample.com/foo
指向同一页面时添加一条重写规则
我当前拥有的重写规则:
RewriteEngine On
RewriteRule ^(.*)/$ /$1/ [R=301,L]
似乎没有任何效果。试试:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/.+/$
RewriteRule ^(.*)$ /$1/ [R=301,L]
您正在使用的正则表达式,^(.*)/$
匹配以斜杠结尾的请求,因此example.com/foo
将不匹配它。尝试:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/.+/$
RewriteRule ^(.*)$ /$1/ [R=301,L]
您正在使用的正则表达式,^(.*)/$
匹配以斜杠结尾的请求,因此example.com/foo
将不匹配该正则表达式。我更喜欢在symfony 1.4中“尾部斜杠”的“内部项目”解决方案:
// project_root/lib/routing/MyProjectNamePatternRouting.class.php:
/**
* fixes URL trailing slashes
*/
class MyProjectNamePatternRouting extends sfPatternRouting
{
/**
* @see sfPatternRouting
*/
public function parse($url) {
$url = rtrim($url, '/'); # trim trailing slashes before actual routing
return parent::parse($url);
}
}
// apps/frontend/config/factories.yml:
all:
...
routing:
class: MyProjectNamePatternRouting
param:
generate_shortest_url: true
extra_parameters_as_query_string: true
...
我更喜欢symfony 1.4中“后续斜线”的“内部项目”解决方案:
// project_root/lib/routing/MyProjectNamePatternRouting.class.php:
/**
* fixes URL trailing slashes
*/
class MyProjectNamePatternRouting extends sfPatternRouting
{
/**
* @see sfPatternRouting
*/
public function parse($url) {
$url = rtrim($url, '/'); # trim trailing slashes before actual routing
return parent::parse($url);
}
}
// apps/frontend/config/factories.yml:
all:
...
routing:
class: MyProjectNamePatternRouting
param:
generate_shortest_url: true
extra_parameters_as_query_string: true
...