guys I'm new with Symfony and I have the follow question to see if this is possible.
Righ now I have an app that runs on Symfony that is located in www.domain.com/app and I want to if a user visits the URL redirect to another website (since a lot of users tries to brute force the login dashboard) but if I put the Symfony app login URL that is www.domain.com/app/dashboard/login the login dashboard appears.
I have to try to do something with .htaccess but with not luck.
Thanks
maybe something like
RewriteRule ^app$ "http://otherwebsite.example.com/$1" [R,L]
in your .htaccess ? The complete login URL will still work because this Rule only catches URLS ending with app
Actually your question is not so Symfony specific. It is more about Rewrite Rules.
Also, why not just answer with an error 404 if somebody accesses /app, (here with optional trailing slash) ?
RewriteRule ^app(\/?)$ - [L,R=404]
to redirect any request you can use return $this->redirect('http://stackoverflow.com');
You have a lot of soulion this one :
public function indexAction()
{
return $this->redirect('http://symfony.com/doc');
}
don't forget to check the documentation:
http://symfony.com/doc/2.8/controller.html#redirecting
Related
Probably this question has been asked before but I cannot seem to find a satisfying answer.
I have the following URLs for my website:
mywebsite.com/profile.php?id=abc
mywebsite.com/profile.php?id=xyz
mywebsite.com/profile.php?id=mno
I would like to create redirects so anyone who will enter this URL
mywebsite.com/abc will redirect to mywebsite.com/profile.php?id=abc
mywebsite.com/xyz will redirect to mywebsite.com/profile.php?id=xyz
mywebsite.com/mno will redirect to mywebsite.com/profile.php?id=mno
I would either the URL to be entered as mywebsite.com/abc and changed to mywebsite.com/profile.php?id=abc in the browser's address bar or remain mywebsite.com/abc.
I know how to do this using the Redirects tool in the Cpanel - but it will be much more efficient for me to do it using PHP and/or PDO rather than creating each one manually.
I know you asked for a php way to do this, but you could easily do it with a .htaccess rule, you could add one rule and it will work for all your urls:
RewriteEngine On
RewriteRule ^([^/]*)$ /profile.php?id=$1 [L]
This will accomplish what you want:
mywebsite.com/mno will redirect to mywebsite.com/profile.php?id=mno
mywebsite.com/abc will redirect to mywebsite.com/profile.php?id=abc
mywebsite.com/xyz will redirect to mywebsite.com/profile.php?id=xyz
mywebsite.com/mno will redirect to mywebsite.com/profile.php?id=mno
If you want to redirect from PHP you can do with headers. For example, create index.php in mywebsite.com/abc which contains
<?php
header("Location: http://mywebsite.com/profile.php?id=abc");
exit;
?>
I'm working with MVC and handling routers and am struggling to apply redirection.
request: site.com/christmas
redirect: site.com/holiday/christmas
do not think I should keep a "controller christmas" to do the redirection
My doubt is at what stage should I perform redirection?
I create a config with the special cases of redirection of separate config?
thanks
This re-write rule might help you..
This rewrites every request that come to site.com/(anything) to site.com/holiday/(anything):
RewriteEngine on
RewriteRule ^([a-zA-Z]+)/?$ /holiday/$1
Just put this in your .htaccess and it will do it's job.
If you want only the site.com/christmas to be redirected try this:
RewriteRule ^christmas/?$ /holiday/christmas
I am using the codeigniter Tank_auth library and I want to remove the "auth' part from all the urls.
http://mysite.dev/auth/login
to
http://mysite.dev/login
Use the routes configuration, add something similar to this to application/config/routes.php:
$route['login'] = 'auth/login';
Once you got this set up, you can make the webserver to redirect users from the old url like this:
RewriteRule ^auth/login http://%{SERVER_NAME}/login [L,R=302]
This one will redirect old url requests to the newly handled /login, you might want to handle https:// or subdirectories in later part of the rule.
The whole setup seems a little hackish, changing the generated urls seem to be a better idea.
It happens that I need to fix a Codeigniter issue urgently while being in no way familiar with the tool.
Simple question: how do I allow links back from Facebook like http://www.xxx.de/?fb_action_ids=4811819099741&fb_action_types=og.likes&fb_source=timeline_og&action_object_map=%7B%224811819099741%22%3A447766801925104%7D&action_type_map=%7B%224811819099741%22%3A%22og.likes%22%7D&action_ref_map=%5B%5D
without creating either the infamous The URI you submitted has disallowed characters - which I can fix by setting $config['permitted_uri_chars'] - and neither a 404 because of the internal redirects of CI.
I'd love to learn of a quick fix for that issue.
If you can use .htaccess you can redirect to wherever. This avoids any CI intricacies.
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^ /index.php/? [L]
https://stackoverflow.com/a/4227616/183254
update: possible working rewrite for nginx
if ($args ~ fb_action_ids=(\d+)){
rewrite ^ http://example.com/ permanent;
}
Set these vars in application/config/config.php:
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = TRUE; // This is normally FALSE
Adjust $config['permitted_uri_chars'] if necessary. Mine are a-z 0-9~%.:_\-#! and work for almost everything.
I'm not sure what you need to do with the fb data, so all I can say is that with those options set, you should, in theory, be able to access the get vars supplied by facebook.
codeigniter expects the first part of the URI to be the controller it loads, then the second will be the method, and every segment after that are the parameters for the method that gets loaded. A fast solution is set up a route with a regular expression like you would in MVC3 and point it to a controller and method. You can then parse the uri from there.
Match ?fb_action_ids and change it to /controller/method/?fb_action_ids and go from there. Perhaps with a little more information I could help you even further but if this works for you this should be the quickest way to get up back up and running without having to reconfigure a bunch of things.
http://ellislab.com/codeigniter/user_guide/general/routing.html
In Zend framework, using the MVC, if A user surf explicitly to http://base/url/index.php instead of just http://base/url, The system thinks the real base url is http://base/url/index.php/ and according to that calculates all the URLs in the system.
So, if I have a controller XXX and action YYY The link will be
http://base/url/index.php/XXX/YYY which is of course wrong.
I am currently solving this by adding a line at index.php:
$_SERVER["REQUEST_URI"]=str_replace('index.php','',$_SERVER["REQUEST_URI"]);
I am wondering if there is a built-in way in ZF to solve this.
You can do it with ZF by using Zend_Controller_Router_Route_Static (phew!), example:
Read the manual page linked above, there are some pretty good examples to be found.
$route = new Zend_Controller_Router_Route_Static(
'index.php',
array('controller' => 'index', 'action' => 'index')
);
$router->addRoute('index', $route);
Can't say I totally disagree with your approach. That said, others may well point out 5000 or so disadvantages. Good luck with that.
Well it really depends on how you want to solve this. As you know the Zend Frameworks build on the front controller pattern, where each request that does not explicitly reference a file in the /public directory is redirected to index.php. So you could basically solve this in a number of ways:
Edit the .htaccess file (or server configuration directive) to rewrite the request to the desired request:
RewriteRule (.*index.php) /error/forbidden?req=$1 // Rewrite to the forbidden action of the error controller.
RewriteRule index.php /index // Rewrite the request to the main controller and action
Add a static route in your bootstrapper as suggested by karim79.
Use mod_rewrite. Something like this should do it:
RewriteRule ^index.php/(.*)$ /$1 [r=301,L]
I don't think you should use a route to do this.
It's kind of a generic problem which shouldn't be solved by this way.
You better should have to do it in your .htaccess, which will offer you a better & easier way to redirect the user to where you want, like to an error page, or to the index.
Here is the documentation page for the mod_rewrite
I've never faced this problem using Zend Framework. just do not link to index.php file. that's it. and when your are giving your application's address to users, just tell them to go to http://base/url/
when the user enters http://base/url/ her request URI is base/url and your .htaccess file routs the request to index.php, but the request IS base/url. you do not need to remove 'index.php' from the request. because it is not there.
when you are trying to generate URLs for links and forms and ..., use the built-in url() view helper to generate your links. like this:
// in some view script
<a href="<?php
echo $this->url( array('controller'=>'targetController','action'=>'targetAction') );
?>" >click</a>
do not worry about the link. Zend will generate a URL for you.
The way I look at this is that if I have a website powered by PHP and a user goes to http://site/index.aspx then I would send a 404.
Even though index.php does exist in theory, it's not a valid URL in my application so I would send a 404 in this case too.