url-routing

Returns 302 error in phpunit when the site redirection works fine

醉酒当歌 提交于 2019-12-13 05:45:08
问题 When doing unit testing using PhpUnit in ZF2, the following message shows up: Failed asserting that 302 matches expected 200 I understand that it shown up because of the redirection command of ZF2: return $this->redirect()->toUrl('/admin/album/add'); But when I access it in the browser, the site works find with the above code. But it fails in the unit testing. What should I have to change? 回答1: A browser is not the same as unit testing or vice versa. Your expectations or results are different

301 Redirect dynamic urls from database in asp.net

☆樱花仙子☆ 提交于 2019-12-13 05:44:36
问题 I have thousands of links which need to be redirect to new URL using 301 Permanent Redirect . I have all these urls in the Database table. I would like to know where should be these URLs should be loaded (only once). And can be used for 301 permanent redirect. Sample URLs: *RequestForURL* *301Redirect* why-me/onboard-experience/food-and-drink-for-all-tastes/family-casual/-> /why-me/family-test/ why-me/onboard-experience/food-and-drink-for-all-tastes/room-service/-> /why-me/onboard-experience

How do I restrict the user from accessing the static html files in a ExpressJS/NodeJS?

天涯浪子 提交于 2019-12-13 04:47:55
问题 Is there any way to detect the request URL of the user and reroute to a particular error page, like for example, I want all the routes to any HTML file (*.html), kind of detect it and want it to be rerouted to an Error page. Also hide it from the user to view it. P.S: Using Express 4 and Latest Node.JS version. app.get('/', function(req,res){ if(req.is('text/html') == true){ res.redirect('/login'); } This doesn't seem to work, I think I am missing the parament in the get request. Please guide

mvccontrib test helper and verifying http post routes and parameters

独自空忆成欢 提交于 2019-12-13 04:39:45
问题 Here's an example. Assuming you have the following action: public AccountController : Controller { [AcceptVerbs(HttpVerbs.Post)] public ActionResult Foo(string id) { return View(); } } And the following route registered: RouteTable.Routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "home", action = "index", id = "" } ); I test it like this: var routeData = "~/account/foo".WithMethod(HttpVerbs.Post); routeData.Values["id"] = "123"; routeData.ShouldMapTo

What's the best way to access a URI variable after a hashtag from php?

天涯浪子 提交于 2019-12-13 04:11:24
问题 I have Javascript updating my URI as below: /index.php?page=list#page=news But I would like to make page=news accessible somehow from my server so that when the URI is copied and pasted, it would go to the news page. What is the best way to do this? I tried $_SERVER['REQUEST_URI'] but everything stored in $_SERVER is before the hash tag. 回答1: You can't. That data, called the fragment, is reserved for client side processing and thus is never sent to the server. The only way to utilize the

Change .php URL with id into .html

淺唱寂寞╮ 提交于 2019-12-13 03:59:18
问题 Given the PHP URL course.php?id=10 I want it to redirect to course.html and I want to use the id=10 on this page. How can I do this? 回答1: You can't cleanly rewrite the url and not include the variable somewhere. You'll need to do something like so: RewriteRule ^([0-9]+)/([^.]+)\.html $2.php?id=$1 [L] Which will work for http://example.com/10/course.html . 回答2: Create a .htaccess file and add the following: RewriteEngine On RewriteRule ^([^.]+)\.html$ $1.php [L] Upload this to the root of your

User-friendly URLs for user profiles in YaF

限于喜欢 提交于 2019-12-13 02:45:33
问题 I'm using YAF Framework and want to make the user's profile link to be user-friendly by using their usernames, if username is abdelhady so I want the url to be: www.mysite.com/abdelhady which of course will route back to something like this: www.mysite.com/profile/get/username/abdelhady I've tried something like this, but it didn't work: $config = array( "community" => array( "type" => "rewrite", "match" => "/:username", "route" => array( 'controller' => "profile", 'action' => "get", ) ) );

Why MVC keeps route values in URL without passing them directly

孤人 提交于 2019-12-13 02:26:41
问题 I have a question. Let's say I have this routes: /Guest/{var1}/{var2} /Guest/{var1}/{var2}/edit When I'm on the /Guest/123/321 page, I have a link to /Guest/123/321/edit?id=1 . There is a form on the page /Guest/123/321/edit?id=1 , which posts itself on the same address. Let's say that my Actions looks like: public ActionResult Index(int var1, int var2) { /* here is some a business logic */ return View(model); } [HttpGet] public ActionResult Edit(int id) { /* here is some a business logic */

Jinja2 url generation

百般思念 提交于 2019-12-13 01:37:14
问题 <a href="{{ url('affiliate', affiliate=object.slug) }}">{{ object.name }} </a> Cause an error: reverse() got an unexpected keyword argument 'affiliate' 回答1: As your url() function seem to be an alias to the Django's reverse() , the function signature is different from the regular template tag. So just use the reverse() syntax: <a href="{{ url('affiliate', args=[object.slug]) }}">{{ object.name }}</a> 来源: https://stackoverflow.com/questions/34712469/jinja2-url-generation

CakePHP redirect routing

被刻印的时光 ゝ 提交于 2019-12-13 01:00:24
问题 In my CakePHP 2.3 application, I want example.com/come/Harry to redirect example.com/myworks/people/Harry . This works, but this connects. Router::connect ('/come/:myname', array('controller' => 'myworks', 'action' => 'people'), array( 'pass' => array('myname') ) ); I need a 301 redirection. I tried this: Router::redirect ('/come/:myname', array('controller' => 'myworks', 'action' => 'people'), array( 'pass' => array('myname') ) ); But it redirected to example.com/myworks/people/ . How can I