jQuery - Address plugin problem - jquery-plugins

I've come across a problem which i cant seem to figure out, i use the jQuery address plugin to store history and enable deep linking, and a typical url after a click would look like this:
http://mysite.com/#!/page
Problem here is i need rid of the last / so i need it to look like this:
http://mysite.com/#!page
I'm using plugin version 1.2 - the latest is 1.4. When i use 1.4 my hashbang #! disappears..
Anyone know why? even so, the updated version produces the same problem.
Reasons to fix this are i use 301 redirects to 'Pretty URL's' if an ?_escaped_fragment_= is requested. So this:
http://mysite.com/data/#!page1
would become:
http://mysite.com/data/page1
currently it does this: mysite.com/data//page1
here is the .htaccess rewrite:
<IfModule mod_rewrite.c>
RewriteEngine on
# Rewrite current-style URLs of the form 'index.php?url=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
</IfModule>
and here is some relevant PHP i use on page load:
if ($fragment = $_GET['_escaped_fragment_']) {
// OPTION 1: if Google is reqesting an '_escaped_fragment_=' page, then redirect to a clean URL
header("Location: $base/$fragment", 1, 301);
exit;
}
Any help on how to make this situation better is appreciated.. I don't want 'use the HTML5 History API' as ive explored this option already.

This line of code can help!
$.address.strict(false);

Related

Get values from wildcard sub-domain and the url using mod_rewrite

I have tried for many days to solve my need. Try to find in google and read at the stackoverflow, but I stil unable to get my answer.
I need to get the subdomain value including the value behind it.
for example:
subdomain_name.domain.com -> will execute domain.com/user.php?subdomain_value=subdomain_name
subdomain_name.domain.com/product_1.html --> will open page domain.com/user.php?page=1&subdomain_value=subdomain_name
I have tried to use code below:
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$
RewriteCond %{REQUEST_URI} !^/user\.php$ [NC]
RewriteRule ^(.*)$ /user.php?subdomain_value=%1
RewriteRule ^product_([0-9]+).html$ /user.php?process=list_produk&page=$1&subdomain=%1
But it failed. When try to open subdomain_name.domain.com/product_1.html, it will keep opening the content of subdomain_name.domain.com
If I removed the code:
RewriteRule ^(.*)$ /user.php?subdomain_value=%1
Then, subdomain_name.domain.com/product_1.html will open the correct page, but the address subdomain_name.domain.com fail to open the correct page.
so, How can I make all of the .htaccess code work fine? I have think very hard and try all possibilities, including added [L], [NC,L], [L,QSA], but all of them failed.
Please help.
Thanks.

Laravel pretty URL

I'm going crazy here! I'm trying to learn Laravel and pretty URLs just don't work.
I have enabled mod_rewrite from my apache config file, I have set AllowOverride to All in my user config file and I have the following in my .htaccess file in public folder of Laravel installation:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
I enter http://localhost/~user/lara/public/index.php/users it works, but with http://localhost/~user/lara/public/users I get 404 Not Found error
The requested URL /Users/user/Sites/lara/public/index.php/users was not found on this server.
You can see that the redirection works fine, as public/users have turned into public/index.php/users but it says not found, even though when I manually enter public/index.php/users it show me the output.
I have read all the related questions on SO, none of the worked for me!
This is most likely caused by the fact that you are changing the document root during a request. From the looks of your URL (with the ~user segment) you are using mod_userdir or something similar, and what these types of plugins do it allow you to map a given URL prefix to a document root that is not the normal one for the server.
As such, you sometimes run into issues like this where the right .htaccess file is found, but its rewritten URL is against the original document root rather than the modified one and so your index.php file cannot be found (maybe, to be honest I don't really know, this is all conjecture). This is also why going directly to index.php/users works - the problem isn't the setup per se, but the mixing of rewrite rules and the change of the document root.
As such, the fix is to use a RewriteBase line, ad the following to the .htccess file:
RewriteBase /~user/lara/public/

Configuring MODx Revolution to work with both http and https

I have a website using MODx Revolution (2.2.10-pl, advanced install), let's call it www.example.com, which I want to be accessible with both http and https.
to achieve this, I tweaked the site_url context setting to be [[++url_scheme]]www.example.com/. Links created using [[~id]] seem to be alright, however, sometimes, the generated links are really weird. My interpretation is that the code to create links programmatically doesn't work with my settings, but I don't know why, or how else I would go about enabling both http and https.
Question first, examples below: How should I set the site_url or any other site/context setting so that links on my site work with both http and https? Optionally, is the behavior I see a bug, or expected behavior given Revolution's tag evaluation semantics?
Misbehavior examples:
When I click on "View" in the manager for a resource with the alias example, the address that is opened is
https://www.example.com/xyz/[[++url_scheme]]www.example.com/example/
where xyz is my manager URL. The expected URL is of course
https://www.example.com/example/
Another case where this happens is for failed logins; my login call looks like this (minus irrelevant parts):
[[!Login? &redirectToOnFailedAuth=`[[++unauthorized_page]]`]]
The unauthorized_page's expected full URL is
https://www.example.com/special/401
but the URL which is opened for a failed login as username is
https://www.example.com/[[++url_scheme]]www.example.com/[[++url_scheme]]www.example.com/special/401?u=username
The second example is the same for http, except for the scheme, of course; I haven't logged into the manager with http.
EDIT
.htaccess at the webroot:
RewriteEngine On
RewriteBase /
# redirect all requests to /en/favicon.ico to /favicon.ico
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en)/favicon.ico$ favicon.ico [L,QSA]
#RewriteRule ^(en|nl|de)/favicon.ico$ favicon.ico [L,QSA]
# redirect all requests to /en/assets* /assets*
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en)/assets(.*)$ assets$2 [L,QSA]
#RewriteRule ^(en|nl|de)/assets(.*)$ assets$2 [L,QSA]
# redirect all other requests to /en/*
# to index.php and set the cultureKey parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
#RewriteRule ^(en|nl|de)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
.htaccess in the manager's directory:
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/xyz/$1
The problem is with $modx->makeUrl(). For example, for the
[[!Login? &redirectToOnFailedAuth=`[[++unauthorized_page]]`]]
call, in core/components/login/controllers/web/Login.php:
public function checkForRedirectOnFailedAuth(modProcessorResponse $response) {
$redirectToOnFailedAuth = $this->getProperty('redirectToOnFailedAuth',false,'isset');
if ($redirectToOnFailedAuth && $redirectToOnFailedAuth != $this->modx->resource->get('id')) {
$p = array(
'u' => $this->dictionary->get('username'),
);
$message = $response->getMessage();
if (!empty($message)) $params['m'] = $message;
$url = $this->modx->makeUrl($redirectToOnFailedAuth,'',$p,'full');
$this->modx->sendRedirect($url);
}
}
the last two lines do a redirect to a URL generated with makeUrl, which will be something like [[++url_scheme]]www.example.com/etc (note: I'm not 100% sure here, as I can't easily look at the raw URL. The conclusions still hold, though). If the URL is simply shown on the page, this is no problem, because MODx will parse the tag before inserting it into the html output. However, as the URL is used directly for the redirect, no such replacement takes place, and the browser interprets it as a relative URL, resulting in target URLs such as https://www.example.com/[[++url_scheme]]www.example.com/etc.
So much for the problem. To avoid this, site_url must be a literal value without any tags in it. As a workaround, I now use the following snippet as the first thing in my template:
$modx->config['site_url'] = $modx->config['url_scheme'] . substr($modx->config['site_url'], strlen('[[++url_scheme]]'));
return '';
together with a [[++site_url]] of
[[++url_scheme]]www.example.com/
Note that some parts of MODx don't seem to notice this update, which is why it's important to still use [[++url_scheme]] in your site_url. As far as I can tell right now, the parts that don't see the update, stuff like [[~id]], work properly with url_scheme.
EDIT this does of course only fix the "View" buttons in the manager if you tweak the manager templates accordingly.
WARNING this is of course very hacky, and not yet tested very well. The fact that some features do not see the overwritten value means that you're introducing an inconsistency into your website, which may lead to subtle errors! If a more clean solution comes up, go for it!

Despite adding QSA to mod_rewrite, $_GET still returning empty variable

UPDATED 2/1/13: This question is really holding me up from getting some work done, so if anyone else has a suggestion, It'd be much appreciated.
I'm trying to make domain.com/notalone/viewpost/5/ act as domain.com/notalone/viewpost.php?id=5
My current .htaccess is this:
RewriteEngine On
RewriteRule ^notalone/viewpost/([0-9]+)/?$ /viewpost.php?id=$1 [QSA]
Currently, the page loads properly when you visit /notalone/viewpost/5/ but it does not pass $_GET['id']
Things I've Tried:
Adding Options -Multiviews ---> Results in a 404
Using Rewritebase / ---> No effect
RewriteRule ^viewpost/([0-9]+)/?$ /viewpost.php?id=$1 [QSA] ---> No effect
You say viewpost.php is in the notalone folder, but you htaccess assumes it is in the root.
So I think it should be:
Options -MultiViews
RewriteRule ^notalone/viewpost/([0-9]+)/?$ /notalone/viewpost.php?id=$1 [QSA]
(Note that I added the multiviews, because that will be your next issue. The fact that the old url worked was because of multiviews.)

mode rewrite redirecting directory to another wont work

alright so i have a need for mode rewrite and i am completely noob/new to it.
I've read sever guide. that explained mode rewrite goes - pattern - redirection - flags.
i am trying to redirect anyone that gets into domain.com/product/ to domain.com/product.php
and pass the variable url=232 however i am first trying to redirect /product/ to product.php
Here is what i got so far.
Options +FollowSymLinks
RewriteEngine On
RewriteRule \/product\/ /product.php
I've started even more basic then that by redirect product.php to index.php and that worked.
am i doing something wrong ?
RewriteEngine On
RewriteBase /
RewriteRule ^product/?$ /product.php?url=232

Resources