pingdom said me :
Remove the following redirect chain if possible:
can you help me ?
https://www.facebook.com/connect/ping?client_id ... onse_type=token%2Csigned_request%2Ccode&sdk=joey
http://staticxx.facebook.com/connect/xd_arbiter/r/lY4eZXm_YWu.js?version=42
Remove the following redirect chain if possible:
https://www.facebook.com/plugins/comments.php?a ... e=en_US&numposts=4&sdk=joey&skin=light&width=600
https://www.facebook.com/plugins/feedback.php?a ... e=en_US&numposts=4&sdk=joey&skin=light&width=600
That seems to all be happening on the facebook.com domain which you don't have any control over, so I don't believe you can fix this.
Related
Hello I need to pull out C0044SGXAU out of the url..
http://www.website.com/Sax-Mat-Rat-Mats-Cat/ce/C0044SGXAU/ref=sr_22?s=cats-rats&ie=UTF8&qid=5425444445&sr=1-1&keywords=animals
Results should be:
C0044SGXAU
Just try with following regex:
([^\/]+)\/[^\/]*$
Maybe the following expression does the job for you (given the /ce/ is always present)
^http.+\/ce\/(\w+)\/?
It works with and without the parameters - See here.
UPDATE
I've gone through the codex docs on the rewrite API and now have the following in my functions.php :
function my_rewrite_rules() {
add_rewrite_rule('(a|b|c|d)/?$', 'index.php?pagename=$matches[1]-overview&myVar=var', 'top');
}
add_action('init', 'my_rewrite_rules');
Yes, I am going to the permalinks page to flush the rules after adjusting. The behavior is the same, the rule above 404s even though the page does exist and I can access it by typing directly into the address bar. However, if I hardcode one of the regex matches like so:
function my_rewrite_rules() {
add_rewrite_rule('(a|b|c|d)/?$', 'index.php?pagename=a-overview&myVar=var', 'top');
}
add_action('init', 'my_rewrite_rules');
then all works as expected, with query vars set correctly. Ideas?
ORIGINAL QUESTION
I've been trying to get Wordpress rewrite rules to work for quite some time now and am absolutely stumped as to why the following code (in functions.php) doesn't work:
function my_rewrite_rules($rules) {
$my_rules = array('(a|b|c|d)/?$' => 'index.php?pagename=$matches[1]-overview&my_var=somevar');
return array_merge($my_rules, $rules);
}
add_filter('page_rewrite_rules', 'my_rewrite_rules');
I have canonical redirects disabled and the rewrite just 404s. If redirecting is enabled, it does go to the correct page, but my query variable is stripped. If I remove '$matches[1]' and replace it with a, b, c, or d, everything works as expected with canonical redirecting disabled. I realize there are a few workarounds but I just want to understand why the following doesn't work? Thanks!
Apparently having the $matches variable directly after the pagename query variable is treated as a special case in the url_to_post() function of Wordpress. Here is a snippet from that code:
if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
// this is a verbose page match, lets check to be sure about it
if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) )
continue;
}
If I read this correctly it seems that Wordpress assumes (incorrectly) that the $matches variable should match the page path. So in your example, if you do not have a page with the name a, b, c or d your rewrite rule will be skipped entirely (continue will be called).
I've deduced this from reading the Wordpress code, but I've not tested my theory (I've actually never worked with Wordpress at all). You could test my theory by making a pages with the names a, b, c, and d and running your code again. If I am correct this should make your rule work. I would suggest not using -overview behind your pagenames, thus solving the problem.
I have been trying to figure this out for nearly 2 hours now and can't get it working so I hope some of you can help me out. Please note I pretty new to PHP and regex.
Ok so I am trying to setup a redirect that will redirect to certain pages based on text in the subdomain. I have wildcards setup for my subdomains and any subdomain URL now redirects to this php file containing the code below.
So if someone comes to anytexthere.domain.com they arrive at domain.com/redirect.php
This php file will be used to send them to the correct relevant URL.
To do this I am going to use subdomains such as anythinghere-1.domain.com and then have my code check what appears in the subdomain after - and before the .domain. If it equals in this case 1 go to whatever URL matches it and so on.
Code so far:
<?php
$host = $_SERVER['SERVER_NAME'];
preg_replace('(?<=-).*?(?=\.)', $host, $matches);
$url = $matches;
switch ($url)
{
case "1":
header("Location: http://www.website.com/page-here/");
break;
case "test":
header("Location: http://www.website.com/this-is-a-test/");
break;
case "another":
header("Location: http://www.website.com/another-page-here/");
break;
default:
header("Location: http://www.website.com");
break;
}
?>
As you can see I have cases there that use text e.g "another" instead of numbers because I will need it to work if I choose to use text or numbers after the - in the subdomain.
This code as it is now is giving me the following errors:
Warning: preg_replace() [function.preg-replace]: Unknown modifier '.' in thelocationhere on line 4
and
Warning: Cannot modify header information - headers already sent by (output started at thelocationhere:4) in thelocationagain on line 22
I believe the second error above has something to do with the default case.
I really appreciate any help with this. I have spent a lot of time searching all over for snippets of code and testing them but I haven't got it to work on my own.
Thanks,
Peter
You have a small mistake - you used preg_replace instead of preg_match. also, you need to pad your regular expression with /. so it should be:
preg_match('/(?<=-).*?(?=\.)/', $host, $matches);
By the way, you didn't mention how you are making everyone who try and access *.domain.com to reach domain.com/redirect.php., but I'm assuming you are using htaccess and the RewriteEngine. You could just directly type it in the RewriteRule.
The "Headers already sent" means some output was sent to the browser. Did you save your file as UTF-8 without BOM? or maybe you've printed something to the browser prior to the redirect?
There could also be some stray spaces at the beginning of the file....
I'm working on a multilingual application that uses IIS7-based url rewriting.
I'd like the following Url actions:
1. fr-ca > index.aspx?l=&lc=fr-ca
2. fr-ca/ > index.aspx?l=&lc=fr-ca
3. fr-ca/568/sometitle > index.aspx?l=568&lc=fr-ca
4. 568/sometitle > > index.aspx?l=568&lc=
Essentially, the initial fr-ca is optional.
My current rule:
<match url="^(fr-ca.)?([^/][0-9]+)?/*" />
Fails on #1
Another attempt:
<match url="^(fr-ca)?(.[0-9]+)?/*" />
Passes all requirements, except the back reference {R:2} gives /568 in this case.
I suppose I could add another rule that adds a / to the end of a fr-ca only, but that doesn't seem right.
Thanks for any help! Regex drives me bonkers.
Should you be doing it this way? Instead of seeing which url they hit (and redirecting to what I presume is a translated version of the page), you could actually check the Accept-Language header... probably even from within that ASP page.
This means that they see the language they want to see it in from the beginning, and without clicking on that dumb little flag at the top of the page. It doesn't rely on GeoIP, or user interaction.
Check it out.
Sorted it out myself.
^(fr-ca)?/?([0-9]+)?
passes:
fr-ca
fr-ca/
fr-ca/9
fr-ca/9/
fr-ca/9/sometitle
fr-ca/9/sometitle/
fr-ca/9/sometitle/anothertitle
9
9/
9/sometitle
9/sometitle/
9/sometitle/anothertitle
Embarrassing as this may be, I've hit a wall with mod_rewrite trying to come up with what seems to be a simple rule.
I'd like to accomplish the following mapping:
/cat/subcat which may have a "?PageId=123" afterwards
should become
/cat.php?cid=148 or (/cat.php?cid=148&PageId=123)
So for example, the following 2 mappings would occur:
/cat/subcat => /cat.php?cid=148 (the 148 part can be ignored, it's taken care of)
/cat/subcat?PageId=2 => /cat.php?cid=148&PageId=2
Note that there's an & in the second clause... The parameter will always be PageId
Can this be done?
Thanks so much in advance!
Apparently a little elbow grease worked (after 5 hours)...
Ends up the rule is just:
^/cat/subcat /cat.php?cid=148 [QSA]
I was missing the QSA component...
-Adam