I've got urlManager rules:
...
'/<slug:(nasha-glavnaya-zagolovok)>' => 'page/page/show',
'/pages/<slug>' => 'page/page/show',
...
all fine.
When I enter to address
/nasha-glavnaya-zagolovok
it opens the page i need
But if I try to open page
/pages/nasha-glavnaya-zagolovok
it also opens the page I need
But content of pages are same.
How i can redirect (with 301 header) from route to pattern if any rule in urlManager mathced?
i cannot give you the complete answer, but you can work make it work like this...
you can use a rule that sends the request to an action which job is just to redirect using CController::redirect()
replace this
'/<slug:(nasha-glavnaya-zagolovok)>' => 'page/page/show',
'/pages/<slug>' => 'page/page/show',
with this
'/<slug:(nasha-glavnaya-zagolovok)>' => 'page/page/show',
'/pages/<slug>' => 'site/redirect',
and redirect the user to /$slug in the 'site/redirect' action
update: you can make it work by writing a new url rule which extends CBaseUrlRule, not sure if you care to take the time to do that if this is the only redirect you want to do though
Related
First off, this is not about a redirect after a POST request via Ajax as I'm aware there're a lot of SO questions regarding this.
What I want is redirecting all requests from / to /app. However, using the following:
/* GET home page. */
router.get('/', function(req, res, next) {
res.redirect('/app');
});
.. it shows the content of the /app route without changing the URL in browser. It stays the same https://example.com/.
Is there a way to actually redirect with a 302 or 301 http status code?
res.redirect takes two arguments (code, location). code corresponds to HTTP status code . By default code is taken as 302 which means The requested resource resides temporarily under a different URI.
Use 301 code for permanent redirect
res.redirect(301, '/app')
I'm looking for help on setting up routes in CakePHP3.4.6 where
urls are variable. For instance, I want the following urls:
/California/Posts/view/Skateboard/Jan2nd/10
/Texas/Posts/view/Truck/Feb10th/35
to connect to
/Posts/view/10
/Posts/view/35
respectively. When doing so, I need the URLs preserved in the browser.
(i.e. browser URL shows /California/Posts/view/Skateboard/Jan2nd/10 while content is served for /Posts/view/10)
Can this be done through configuring routes.php?
Any advice will be most appreciated.
I tried using rewrite rules in webroot/.htaccess such as:
RewriteRule ^[^/]+/Posts/view/[^/]+/[^/]+/(\d+)$ /Posts/view/$1 [L]
But this just ends up in 404 errors. The pattern match seems to be correct as the following rule works:
RewriteRule ^[^/]+/Posts/view/[^/]+/[^/]+/(\d+)$ http://www.google.com [L]
Thanks,
Managed to figure this out.
$routes->connect('/:state/Posts/view/:title/:date/:id',
['controller' => 'Posts', 'action' => 'view'],
['id' => '\d+', 'pass' => ['id']]
Did the job
I need to redirect help.mydomain.com/a-page to /pages/a-page without using Nginx or Apache redirects and only through Rails 3 routes.
The key here is the help subdomain determining that /pages/ should be dropped from the route although the view is under the /views/pages/
Any help is appreciated.
Try this:
match "/:page_name" => redirect("/pages/%{page_name}"), :constraints => { :subdomain => /help/ }
Is there a way to set the default root routes in rails to be one of my controller action and showing in the url rather than the root "/" ?
Say I have a "Computer" controller with a "index" action.
When my user login to my application, I want the url to be
http://localhost:3000/computer/index rather than http://localhost:3000/
root :to => "computers#index"
does the latter one, how can I make the default root url to be something like the prior one ?
UPDATE: a better way would be
root :to => redirect(/path)
The simplest way would be to change which URL your users get re-directed to after they successfully log in.
You could also add a forced re-direct in your controller:
# routes.rb
root :to => "computers#force_redirect"
# computers_controller.rb
def force_redirect
redirect_to '/computers/index'
end
I am on abc.domainname.com
Now in any action
I want to redirect to a page domainname.com without subdomain.
How can I do this?
I tried like index_path(:subdomain => false).
If I hardcode like redirect_to("http://domainname.com"). Then it works.
I did in this way,
index_url(:subdomain => false)
And it works!