I am trying to create routes within an app that I am working on like the following example:
http://www.example.com/entrepreneur.com/article/251468
My hope is to basically load an external page into an iframe by adding our domain to the URL. It needs to be without storing the external url in a database because I need every website accessable in this way. How can I do this?
You need a route with a wildcard like this:
get 'url/*args', to: 'your_controller#your_action'
See http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments
I would suggest you namespace the route under some keyword to catch this wildcard route explicitly (hence url in the above).
You may need to tweak the route to allow periods to prevent them from becoming the format. I forget if that's true for these or not.
Related
I am trying to do something very simple, but can't seem to find a way to do it. What I want is to have a URL in the form of /en/products/accessories+software internally route to /en/products?accessories+software.
/en/products is an existing page, whatever comes after are basically filters, which are appended to the URL so they can be linked directly. Now it works by appending it as query parameters, but using /filtersHere would be preferred. But this of course results in a 404 error.
Site is running D9.
Why not use Drupal's Routing system and make dynamic arguments on URL?
In the module.routing.yml, something like below should do:
module.mypath:
# Dynamic arguments enclosed in { }.
path: '/book/export/{type}/{node}'
defaults:
_controller: '\Drupal\module\Controller\MyController::index'
More details available in the official doc:
Drupal - Structure of routes
I have a website built from Ember.js. A user can access a page through URL http://..../view?showTitle=true. However I don't want to explicitly expose the parameter showTitle=true to the user (meaning user will only see http://..../view). This URL is automatically generated and serves as a redirect destination URL. So, I have to remove it manually somewhere before the page load. But I still need this value of this query parameter to query data. Is there a way to achieve that (A example would be great)? What about do it without refreshing the router?
Actually, an example of your scenario would be greater :)
There are some other ways to store data while transitioning to a route. Such as: storing the params in transition object or storing the value in a service. Create a redirection route, use beforeModel hook to grab the value from query params then do a redirection to the real route.
A working example is: ember-twiddle-1
By the way, even if you don't describe your queryParamsin your routes, you can access them via transition.queryParams. This seems a bit hacky. But it works: ember-twiddle-2 (Note: It doesn't work in the same route.)
Updated:
At the setupController hook you can override the controller parameters. So you can remove the parameters from the url. ember-twiddle-3
In a site I'm developing I have a page that presents a post based on the variable in the url:
http://www.mywebsite.com?id=18
So this would load the post who's ID is 18 in the mySQL database.
I would like the create the same effect, but with the url being something like:
http://www.mywebsite.com/articles/title-of-article-18/
Would there be a way to create these pages on the fly with dynamic post content, where the url would originally be created by:
"http://www.mywebsite.com/articles/" + postTitle
You are looking for mod_rewrite and rewriting of urls via htaccess.
What it does is it takes patterns from your url, and the htaccess file detects the pattern redirects that to http://www.mywebsite.com?id=18. Users still see the nice url.
The directory /articles/title-of-article-18/ will not actually exist, and the user never really reaches that location because the htaccess secretly changes the url that the server processes.
See
http://en.wikipedia.org/wiki/Rewrite_engine
or a random tutorial I found:
http://www.blogstorm.co.uk/htaccess-mod_rewrite-ultimate-guide/
try url-rewriting
http://www.simple-talk.com/dotnet/asp.net/a-complete-url-rewriting-solution-for-asp.net-2.0/
I'd like to have one module controller implement the different action methods, but I don't want the URLs to come out like
www.example.com/module/index/action1
www.example.com/module/index/action2
www.example.com/module/index/action3
where /index/ takes us to the "IndexController". To have the URLs like I want
www.example.com/module/action1
www.example.com/module/action2
www.example.com/module/action3
I would need to create a controller class for every action method. What is the best way to get the URLs I want with the different action methods in one nice class/file/controller? I was wondering if there was a way besides URL rewrites. If not, could you point me to a good URL rewriting tutorial for Magento?
There is no real reason to violate Magento reuter/controller/action scheme. For any deviation they created the URL rewrites functional.
You can create Url rewrite even omitting the module part. Creating URL rewrites is really simple, I don't think you need tutorial for that, just open admin panel, go to Catalog->Url Rewrites Management. Click on create new rewrite, choose Custom type, add the desired uri part to Request Path (module/action), and the actual uri to the Target Path (module/controller/action).
If you don't want to do an URL rewrite at the web server, you can also do, essentially, an URL rewrite inside Magento's code. For example, you can override the function Match within Mage_Core_Controller_Varien_Router_Standard like so:
/* after getting the controller name and action name... */
if ((strcmp($module, 'myModuleName') == 0) && (strcmp($action, 'index') == 0)) {
$action = $controller;
$controller = 'index';
}
/* before checking if this place should be secure and instantiate controller class
I think URL rewrite at the web server will be cleaner and more manageable, though.
If you are using Magento's URL rewrite, you'll probably need to specify a rule for every action, such as:
Type: custom
Request Path: myModuleName/hello
Target Path: myModuleName/index/hello
You can specify these URL rewrite rules in the admin, under Catalog > URL Rewrite Management
I'm looking for solution to invoke backbone action for particular route in my app.
I know that it's possible to match url like:
localhost:3000/#posts/1
But what if I need to match url like:
localhost:3000/posts/1
Opt-in to the new HTML history API / pushState, e.g.:
Backbone.history.start( { pushState : true } );
Depending on your application, you may want to take other steps as well, e.g.:
Note that using real URLs requires your web server to be able to correctly render those pages, so back-end changes are required as well.
http://backbonejs.org/#History