Discussion:
Rewrite rules after unknown url structure
Jesse Friedman
2013-10-22 15:49:11 UTC
Permalink
Hi Everyone

Thanks in advance for any help.

We have a plugin that turns all of our pages and CPT's into SEM landing
pages simply by appending ?sem=true to the end of the url. Google has
recently decided to start declining our campaigns because of this
parameter.

So right now I have
domain.com/coverage/vehicle/?sem=true

I need it to be
domain.com/coverage/vehicle/sem

I have the following code, which works well to a point.

function add_query_vars($aVars) {
$aVars[] = "sid"; // represents the name of the product category as
shown in the URL
return $aVars;
}

add_filter('query_vars', 'add_query_vars');

function add_rewrite_rules($aRules) {
$aNewRules = array('sample-page/([^/]+)/?$' =>
'index.php?pagename=sample-page&sid=$matches[1]');
$aRules = $aNewRules + $aRules;
return $aRules;
}

add_filter('rewrite_rules_array', 'add_rewrite_rules');

The problem is that, this code assumes this parameter is only going to be
used on pages where pagename=='sample-page'

I need to be able to get the var on any page, post, cpt, etc...

I'm find with doing

domain.com/sem/sample-page


Can someone point me in the right direction?
--
thanks

*jesse friedman*
jes.se.com *
*
Book: Web Designers Guide to WordPress -
http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
Twitter: @professor <http://twitter.com/professor>
Facebook: Like<https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
William Satterwhite
2013-10-22 15:54:14 UTC
Permalink
Are your SEM landing pages actual pages or another custom post type? If
they're another custom post type you could add an additional parameter
specifying the post type in your add_rewrite_rules function.

$aNewRules = array('sample-page/([^/]+)/?$' =>
'index.php?*post_type=sem_pages*&pagename=sample-page&sid=$matches[1]');
Post by Jesse Friedman
Hi Everyone
Thanks in advance for any help.
We have a plugin that turns all of our pages and CPT's into SEM landing
pages simply by appending ?sem=true to the end of the url. Google has
recently decided to start declining our campaigns because of this
parameter.
So right now I have
domain.com/coverage/vehicle/?sem=true
I need it to be
domain.com/coverage/vehicle/sem
I have the following code, which works well to a point.
function add_query_vars($aVars) {
$aVars[] = "sid"; // represents the name of the product category as
shown in the URL
return $aVars;
}
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($aRules) {
$aNewRules = array('sample-page/([^/]+)/?$' =>
'index.php?pagename=sample-page&sid=$matches[1]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
The problem is that, this code assumes this parameter is only going to be
used on pages where pagename=='sample-page'
I need to be able to get the var on any page, post, cpt, etc...
I'm find with doing
domain.com/sem/sample-page
Can someone point me in the right direction?
--
thanks
*jesse friedman*
jes.se.com *
*
Book: Web Designers Guide to WordPress -
http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
Facebook: Like<
https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Hunter Satterwhite
http://linkedin.com/in/hsatterwhite
(252) 762-5177
Jesse Friedman
2013-10-22 15:58:20 UTC
Permalink
Hey Hunter

The SEM landing pages don't really exist. Basically if that parameter is
set to True it just strips out the nav, sidebar, and footer and replaces it
with other markup. So every post, page, cpt can potentially be an SEM
landing page.

Jesse


On Tue, Oct 22, 2013 at 11:54 AM, William Satterwhite <
Post by William Satterwhite
Are your SEM landing pages actual pages or another custom post type? If
they're another custom post type you could add an additional parameter
specifying the post type in your add_rewrite_rules function.
$aNewRules = array('sample-page/([^/]+)/?$' =>
'index.php?*post_type=sem_pages*&pagename=sample-page&sid=$matches[1]');
Post by Jesse Friedman
Hi Everyone
Thanks in advance for any help.
We have a plugin that turns all of our pages and CPT's into SEM landing
pages simply by appending ?sem=true to the end of the url. Google has
recently decided to start declining our campaigns because of this
parameter.
So right now I have
domain.com/coverage/vehicle/?sem=true
I need it to be
domain.com/coverage/vehicle/sem
I have the following code, which works well to a point.
function add_query_vars($aVars) {
$aVars[] = "sid"; // represents the name of the product category
as
Post by Jesse Friedman
shown in the URL
return $aVars;
}
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($aRules) {
$aNewRules = array('sample-page/([^/]+)/?$' =>
'index.php?pagename=sample-page&sid=$matches[1]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
The problem is that, this code assumes this parameter is only going to be
used on pages where pagename=='sample-page'
I need to be able to get the var on any page, post, cpt, etc...
I'm find with doing
domain.com/sem/sample-page
Can someone point me in the right direction?
--
thanks
*jesse friedman*
jes.se.com *
*
Book: Web Designers Guide to WordPress -
http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
Facebook: Like<
https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Hunter Satterwhite
http://linkedin.com/in/hsatterwhite
(252) 762-5177
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
thanks

*jesse friedman*
jes.se.com *
*
Book: Web Designers Guide to WordPress -
http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
Twitter: @professor <http://twitter.com/professor>
Facebook: Like<https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
William Satterwhite
2013-10-22 16:07:43 UTC
Permalink
Ah I see. I've done something similar, but I was actually querying for a
custom post type, but the requested URL utilized the existing page URL
structure. And FWIW I was using a custom query_var as well.

This being the live example that I'm referring to:
http://michiganfireworks.com/by-date/2013-11-01/

The ISO date is the custom query var, but the by-date portion is using your
normal page URL structure.

I agree with John; look in to endpoints.
Post by Jesse Friedman
Hey Hunter
The SEM landing pages don't really exist. Basically if that parameter is
set to True it just strips out the nav, sidebar, and footer and replaces it
with other markup. So every post, page, cpt can potentially be an SEM
landing page.
Jesse
On Tue, Oct 22, 2013 at 11:54 AM, William Satterwhite <
Post by William Satterwhite
Are your SEM landing pages actual pages or another custom post type? If
they're another custom post type you could add an additional parameter
specifying the post type in your add_rewrite_rules function.
$aNewRules = array('sample-page/([^/]+)/?$' =>
'index.php?*post_type=sem_pages*&pagename=sample-page&sid=$matches[1]');
Post by Jesse Friedman
Hi Everyone
Thanks in advance for any help.
We have a plugin that turns all of our pages and CPT's into SEM landing
pages simply by appending ?sem=true to the end of the url. Google has
recently decided to start declining our campaigns because of this
parameter.
So right now I have
domain.com/coverage/vehicle/?sem=true
I need it to be
domain.com/coverage/vehicle/sem
I have the following code, which works well to a point.
function add_query_vars($aVars) {
$aVars[] = "sid"; // represents the name of the product category
as
Post by Jesse Friedman
shown in the URL
return $aVars;
}
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($aRules) {
$aNewRules = array('sample-page/([^/]+)/?$' =>
'index.php?pagename=sample-page&sid=$matches[1]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
The problem is that, this code assumes this parameter is only going to
be
Post by William Satterwhite
Post by Jesse Friedman
used on pages where pagename=='sample-page'
I need to be able to get the var on any page, post, cpt, etc...
I'm find with doing
domain.com/sem/sample-page
Can someone point me in the right direction?
--
thanks
*jesse friedman*
jes.se.com *
*
Book: Web Designers Guide to WordPress -
http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
Facebook: Like<
https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Hunter Satterwhite
http://linkedin.com/in/hsatterwhite
(252) 762-5177
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
thanks
*jesse friedman*
jes.se.com *
*
Book: Web Designers Guide to WordPress -
http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
Facebook: Like<
https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Hunter Satterwhite
http://linkedin.com/in/hsatterwhite
(252) 762-5177
Jesse Friedman
2013-10-22 16:20:14 UTC
Permalink
John and Hunter

Thanks for the help. The endpoints did it.

3 line of code

public function custom_sem_rewrite_rule(){

add_rewrite_endpoint( 'sem', EP_PERMALINK | EP_PAGES );
}


On Tue, Oct 22, 2013 at 12:07 PM, William Satterwhite <
Post by William Satterwhite
Ah I see. I've done something similar, but I was actually querying for a
custom post type, but the requested URL utilized the existing page URL
structure. And FWIW I was using a custom query_var as well.
http://michiganfireworks.com/by-date/2013-11-01/
The ISO date is the custom query var, but the by-date portion is using your
normal page URL structure.
I agree with John; look in to endpoints.
Post by Jesse Friedman
Hey Hunter
The SEM landing pages don't really exist. Basically if that parameter is
set to True it just strips out the nav, sidebar, and footer and replaces
it
Post by Jesse Friedman
with other markup. So every post, page, cpt can potentially be an SEM
landing page.
Jesse
On Tue, Oct 22, 2013 at 11:54 AM, William Satterwhite <
Post by William Satterwhite
Are your SEM landing pages actual pages or another custom post type? If
they're another custom post type you could add an additional parameter
specifying the post type in your add_rewrite_rules function.
$aNewRules = array('sample-page/([^/]+)/?$' =>
'index.php?*post_type=sem_pages*&pagename=sample-page&sid=$matches[1]');
Post by Jesse Friedman
Post by William Satterwhite
Post by Jesse Friedman
Hi Everyone
Thanks in advance for any help.
We have a plugin that turns all of our pages and CPT's into SEM
landing
Post by Jesse Friedman
Post by William Satterwhite
Post by Jesse Friedman
pages simply by appending ?sem=true to the end of the url. Google
has
Post by Jesse Friedman
Post by William Satterwhite
Post by Jesse Friedman
recently decided to start declining our campaigns because of this
parameter.
So right now I have
domain.com/coverage/vehicle/?sem=true
I need it to be
domain.com/coverage/vehicle/sem
I have the following code, which works well to a point.
function add_query_vars($aVars) {
$aVars[] = "sid"; // represents the name of the product
category
Post by Jesse Friedman
Post by William Satterwhite
as
Post by Jesse Friedman
shown in the URL
return $aVars;
}
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($aRules) {
$aNewRules = array('sample-page/([^/]+)/?$' =>
'index.php?pagename=sample-page&sid=$matches[1]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
The problem is that, this code assumes this parameter is only going
to
Post by Jesse Friedman
be
Post by William Satterwhite
Post by Jesse Friedman
used on pages where pagename=='sample-page'
I need to be able to get the var on any page, post, cpt, etc...
I'm find with doing
domain.com/sem/sample-page
Can someone point me in the right direction?
--
thanks
*jesse friedman*
jes.se.com *
*
Book: Web Designers Guide to WordPress -
http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
Facebook: Like<
https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Hunter Satterwhite
http://linkedin.com/in/hsatterwhite
(252) 762-5177
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
thanks
*jesse friedman*
jes.se.com *
*
Book: Web Designers Guide to WordPress -
http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
Facebook: Like<
https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Hunter Satterwhite
http://linkedin.com/in/hsatterwhite
(252) 762-5177
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
thanks
*
*
*jesse friedman*
jes.se.com *
*
Book: Web Designers Guide to WordPress -
http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
Twitter: @professor <http://twitter.com/professor>
Facebook: Like<https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
John Blackbourn
2013-10-22 15:58:43 UTC
Permalink
You should look at rewrite endpoints.
http://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint
Post by Jesse Friedman
Hi Everyone
Thanks in advance for any help.
We have a plugin that turns all of our pages and CPT's into SEM landing
pages simply by appending ?sem=true to the end of the url. Google has
recently decided to start declining our campaigns because of this
parameter.
So right now I have
domain.com/coverage/vehicle/?sem=true
I need it to be
domain.com/coverage/vehicle/sem
I have the following code, which works well to a point.
function add_query_vars($aVars) {
$aVars[] = "sid"; // represents the name of the product category as
shown in the URL
return $aVars;
}
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($aRules) {
$aNewRules = array('sample-page/([^/]+)/?$' =>
'index.php?pagename=sample-page&sid=$matches[1]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
The problem is that, this code assumes this parameter is only going to be
used on pages where pagename=='sample-page'
I need to be able to get the var on any page, post, cpt, etc...
I'm find with doing
domain.com/sem/sample-page
Can someone point me in the right direction?
--
thanks
*jesse friedman*
jes.se.com *
*
Book: Web Designers Guide to WordPress -
http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
Facebook: Like<
https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...