I have a single page site. My page has multi section. I define sections with #. for example detail section has a url like http://bamap.ir/#/details.
I want to rout some urls as follow:
http://bamap.ir/details go to http://bamap.ir/#/details
http://bamap.ir/user-authentication go to http://bamap.ir/#/user-authentication
...
How can I rout this urls with .htacccess?
I think you should look at the History API that HTML5 provides: https://www.w3.org/TR/html5/browsers.html#the-history-interface
Tfunction removeHash () {
var scrollV, scrollH, loc = window.location;
if ("pushState" in history)
history.pushState("", document.title, loc.pathname + loc.search);
else {
// Prevent scrolling by storing the page's current scroll offset
scrollV = document.body.scrollTop;
scrollH = document.body.scrollLeft;
loc.hash = "";
// Restore the scroll offset, should be flicker free
document.body.scrollTop = scrollV;
document.body.scrollLeft = scrollH;
}
}
quoting the answer here
Rewriting to fregment is imposible as # is not sent to the server. However you could redirect any uri to fregment using the R flag.
RewriteEngine on
RewriteRule ^detail/?$ /#/detail [NE,R]
This will redirect you to /#/detail if you go to /detail .
Related
Hi I want to change my current product URL structure to a new one but I want to keep my old ones working because of people who have linked to my products.
How can I do this without manually creating a 301 redirect for each product?
Not sure what Prestashop version you have, just tried in a 1.6.1.6
You can you this override:
<?php
class Dispatcher extends DispatcherCore
{
protected function loadRoutes($id_shop = null)
{
parent::loadRoutes($id_shop);
$language_ids = Language::getIDs();
if (isset($context->language) && !in_array($context->language->id, $language_ids)) {
$language_ids[] = (int)$context->language->id;
}
foreach ($language_ids as $id_lang) {
foreach ($this->default_routes as $id => $route) {
if($id == "product_rule")
$this->addRoute(
'product_rule2',
'{id}-{rewrite}{-:ean13}.xhtml',
'product',
$id_lang,
$route['keywords'],
isset($route['params']) ? $route['params'] : array(),
$id_shop
);
}
}
}
}
In this case I used a second rule for xhtml (without this override it gave a 404). You can change {id}-{rewrite}{-:ean13}.xhtml to the rule you have, then change the rules in SEO to want you want the new one to be.
Please write your ps version. If you use 1.5 or above?
Do you use this structure now {category:/}{id}-{rewrite}{-:ean13}.html ? or
{category:/}{rewrite}{-:ean13}.html or this {category:/}{rewrite}.html
please write more details
depends on it just make htaccess rule
([0-9]+) for id
(.*) for rewrite
and please use RedirectMatch permanent
and set to the result by $1, $2, etc
that guide must help to understand the htaccess url rewriting https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
I want to send users who use a country code in their adressbar to be redirected to the right subpage by using the htaccess file.
for example:
www.example.nl
redirect to:
www.example.com/nl
Any suggestions?
I would suggest you to use the GeoIP service [PHP] to find out the country of your visitor and then do the redirect.
include("geoipcity.inc");
include("geoipregionvars.php");
$gi = geoip_open("/usr/local/share/GeoIP/GeoIPCity.dat",GEOIP_STANDARD);
$getcountry = geoip_record_by_addr($gi,$_SERVER['REMOTE_ADDR']);
if ( $getcountry->country_code == "NL" ) {
header('Location: www.example.com/nl');
}
Like this for NL Redirect
I am learning codeigniter these days. I have done a website for my own use a couple of days ago where i have just applied pagination today but it seems there is problem with my url rewriting.
Here is my action inside my controller which grabs list of authors in a category
`public function index() {
$data['main_content'] = "templates/public/audio/author_view";
$data['authors'] = $this->author_model->get_authors();
$this->load->view("templates/public/template",$data);
}`
Here is my function that grabs value from db located inside my author model
`public function get_authors($type = 0) {
$this->db->select("author.name,author.image,author.slug");
$this->db->from("author");
$this->db->join("album","author.id = album.author_id");
$this->db->where("album.mime_type",$type);
$this->db->group_by("author.name");
$query = $this->db->get();
return $query->result();
}`
When i clicked on one of author grabbed it open all albums of selected author. then url looks link www.xyz.com/audio/album-nameHere is my code for this route.
$route['audio/(:any)'] = "audio/view_author_album";
At this stage it works fine. But now today when i applied pagination i found that this route will not do more work for me. I have added pagination in my index action Below you can see my code
public function index() {
$config['base_url'] = "http://localhost/mywebsite/audio/index/";
$config['total_rows'] = $this->author_model->get_total_rows();
$config['per_page'] = 1;
$this->pagination->initialize($config);
$data['main_content'] = "templates/public/audio/author_view";
$data['authors'] = $this->author_model->get_authors($config['per_page'], $this->uri->segment(3));
$this->load->view("templates/public/template",$data);
}
This open the details http://localhost/mysite/audio/index/2
against this url my route rule $route['audio/(:any)/(:any)'] = "audio/view_album_details"; works. It should grab the next page instead of my detail view. And url should be something like http://localhost/mysite/audio/2
I also tried $route['audio/(:num)'] = "audio/;
I will highly appropriate if anyone can help me in solving this problem.
i encounter the same issue and i solve it by using two same router
$route['a-b-c/([a-z0-9-]+)/([0-9]*)'] = "product/category/$1";
$route['a-b-c/([a-z0-9-]+)'] = "product/category/";
I'm trying to submit a drupal 6 form PIA to a third party site for processesing, but after submitting the form, I need to redirect to a thank you page within my own site.
I've read this post - Drupal form submission to a 3rd party website
but i'm nor sure how to set up the redirect properly.
this is my code:
$form_state['#action'] = 'external site.com';
$form['#redirect'] = 'thankyou.com';
thanks
Make sure the redirect is the last step. Something like this:
function my_module_form {
$form['#action'] = 'some.external.site';
# Store the redirect in a value element, maybe we need some data
# which are passed to the form, like a user ID, node ID etc.
# So lets store the link in a value element
$form['redirect_link'] = array(
'#type' => 'value',
'#value' => url('some.redirect.page'),
);
}
function my_module_form_validate ($form, &$form_state) {
# Do some validation stuff...
}
function my_module_form_submit($form, &$form_state) {
# show some confirmation message...
drupal_set_message(t('Successfully sent your data into space.'));
# And finally the redirect...
# The 'redirect_link' value was passed internally, without being sent
# to the browser so we can safely use it.
$form_state['redirect'] = $form_state['values']['redirect_link']
}
Redirect property is also set in $form_state.
$form_state['redirect'] = 'some.com';
Since I'm only trying to send informtaion to a third party and not actually redirecting the page after form submission to a third party site.
I got the right answers tot he wrong question.
This is what I ended up using that worked for me:
$url = 'http://thirdpartyurl';
$headers = array('Content-Type' => 'application/x-www-form-urlencoded');
$data = drupal_query_string_encode($pass_the_form_info);
drupal_http_request($url, $headers, 'POST', $data);
I was wondering if this was possible in mod_rewrite, and if anyone knows the syntax for it.
Browser receives:
http://example.com/video/my-first-vid/
mod_rewrite redirects to:
http://example.com/#/video/my-first-vid/
Thanks!
It seems you can't use mod_rewrite for redirecting to /#/video/my-first-vid/ as the # sign is urlencoded and it will redirect to http://example.com/%23/video/my-first-vid/ which obviously isn't what you're looking for. I tested this couple of days before on Apache 1.3.
You may create a separate script(s) for redirection. Add a new rules for this:
RewriteRule ^video/?$ /redirector.php?page=video [NC,L,QSA]
RewriteRule ^video/(.*)$ /redirector.php?page=video&subpage=$1 [NC,L,QSA]
But you might also need to parse the query string manually as it could be smth like:
/video/my-first-vid/?refID=test
Here's some simple example on PHP:
<?php
$page = (isset($_REQUEST["page"])) ? trim($_REQUEST["page"]) : "";
$subPage = (isset($_REQUEST["subpage"])) ? trim($_REQUEST["subpage"]) : "";
// setting the redirect URL, your conditions here
if ($page == "video")
{
$url = "/#/video/" . $subPage;
}
else
{
$url = "/"; // some default url
}
header("Location: " . $url);
exit;
?>
I'm not sure about embedding the '#' in the URI, since that's typically a fragment identifier, but you could try this:
RewriteRule "^(?<!#/)(.*)" "#/$1" [R=301,L]
That should redirect anything that doesn't have a '/#' in front of it to the same location with '/#' in front of it.