How to create custom SEO addresses in WordPress 4.0?

I am running WordPress 4.0 on a Windows Server that has PHP enabled. The blog works fine. Although upon installation, and with the Permalinks Setting set to "post name", the address of any particular page on my site always begins with index.php - such as:

http://mydomain.com/index.php/book-detail/

I'm not concerned about that, although it should also be noted that WordPress did not create an .htaccess file but perhaps that's not significant either.

My problem: I would like to set up an .htaccess file so that any link such as:
http://mydomain.com/index.php/book-detail/?booktitle=my-book-title&isbn=12345

...would go to the book detail page and the full address would resolve to:
http://mydomain.com/index.php/book-detail/12345/my-book-title/

I tried using various examples I found by Googling this issues, but they didn't seem to kick in at all - I think the examples I found were not WordPress specific. Can anyone advise on how this could be accomplished in WordPress 4.0?

thanks experts!
LVL 1
rascalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason C. LevineNo oneCommented:
the address of any particular page on my site always begins with index.php - such as: http://mydomain.com/index.php/book-detail/ I'm not concerned about that,

Just FYI, this happens when you run WordPress on IIS.  The permalinks require mod_rewrite, which isn't present in IIS.  You can instead use the web.config file to do something similar:

http://codex.wordpress.org/Using_Permalinks#Permalinks_without_mod_rewrite

although it should also be noted that WordPress did not create an .htaccess file but perhaps that's not significant either.

It might be...depends on if you are on IIS or not.  If you are not on IIS, you may want to troubleshoot things.

I tried using various examples I found by Googling this issues, but they didn't seem to kick in at all - I think the examples I found were not WordPress specific. Can anyone advise on how this could be accomplished in WordPress 4.0?

What did you try?  Can you post samples here?
0
rascalAuthor Commented:
Thanks Jason,
That explains the issue with the index.php (I am running our test version of the site on IIS, but the live version resides on a Linux server so that version does have an .htaccess file).

Here is the original .htaccess file contained on the live site:

# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Open in new window


The address of the book detail page on the live site is http://mydomain.com/book-detail/
I would like to be able to create a hyperlink that looks like:
http://mydomain.com/book-detail/?isbn=12345&booktitle=my-title and have it go to the book detail page and the address bar show the address as http://mydomain.com/book-detail/12345/my-title/

Here is what I tried on the live site:

# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^book-detail/([0-9]+)/([a-zA-Z]+)/$ /book-detail/?isbn=$1&booktitle=$2
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Open in new window


The above seems to just be ignored. It doesn't rewrite my url. I'm also concerned that since it's inside the WordPress block, it would get overwritten if the permalinks were re-saved from the WordPress admin area, but I'll deal with that once I get the correct syntax.
0
rascalAuthor Commented:
I have also tried using the following within WordPress' functions.php and it also doesn't work:

add_filter( 'query_vars', 'mjf_query_vars' );
function mjf_query_vars( $query_vars )
{
    $query_vars[] = 'bookdetailisbn';
    $query_vars[] = 'bookdetailtitle';
    return $query_vars;
}
add_action( 'init', 'mjf_init_detail_page' );
function mjf_init_detail_page()
{
    add_rewrite_rule('^bookdetail/([^/]*)/([^/]*)/?','index.php?pagename=bookdetail&bookdetailisbn=$matches[1]&bookdetailtitle=$matches[2]','top');
}

Open in new window


And I tried this approach as well:

add_action( 'init', 'mjf_init_detail_page' );
function mjf_init_detail_page()
{
    add_rewrite_rule('^bookdetail/([^/]*)/([^/]*)/?','index.php?pagename=bookdetail&bookdetailisbn=$matches[1]&bookdetailtitle=$matches[2]','top');
    add_rewrite_tag('%bookdetailisbn%', '([^&]+)');
    add_rewrite_tag('%bookdetailtitle%', '([^&]+)');
}

Open in new window

0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Jason C. LevineNo oneCommented:
So the add_rewrite stuff in WordPress IS the way to do it.  However, we've found that merely adding the code is insufficient:

1) Add code to functions.php; save it.
2) Disable all permalinks (Settings | Permalinks | Default)
3) Re-enable permalinks (Settings | Permalinks | How it was before)

The disable/re-enable seems to be necessary to get the code to kick in.   Give me a few minutes and I will post a sample of how we do it.
0
Jason C. LevineNo oneCommented:
Okay, here is our code.  We do something a little different from you, though.  In our case, we take domain.com/something/IDslug and convert it back to domain.com/something/?id=xxxxx for lookup purposes.   The code works, though, so you should be able to adapt it for your needs.

No code needed in .htaccess.

functions.php:

add_action( "init", "pleasing_permalinks" );
function pleasing_permalinks() {
	//register custom query variables
	add_rewrite_tag( '%hash%', '([^&]+)' );
	add_rewrite_tag( '%action%', '([^&]+)' );

	add_rewrite_rule(
		'^meetings/faculty/([^/]+)/?$',
		'index.php?pagename=meetings/faculty&hash=$matches[1]',
		'top'
	);
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rascalAuthor Commented:
Thanks Jason,
Although I am wondering if these just might not work on our test site because we're running IIS and that pesky index.php is always getting explicitly displayed on our URL address bar in our browser?

We did find a work-around:

The target page we're interested in is http://mydomain.com/bookdetail/

So we are just manually constructing our hyperlinks as http://mydomain.com/bookdetail/12345/title-of-book/

By doing this, when a user clicks on that link, it still takes them to the http://mydomain.com/bookdetail/ page because apparently WordPress tries to resolve as much of the URL as it can and just takes you to the last portion of the URL it can resolve, which takes you to the book detail page. And, it leaves the remaining part of the URL intact. So on the bookdetail page, we just read the 12345 (the book's ISBN) and use it to fetch and display the appropriate book.
0
Jason C. LevineNo oneCommented:
Although I am wondering if these just might not work on our test site because we're running IIS and that pesky index.php is always getting explicitly displayed on our URL address bar in our browser?

The .htaccess solutions you tried won't work with IIS.  The internal functions.php should but you still need to clear out the old rules per my instructions.  If they don't work from that point, it's due to poor syntax.

We did find a work-around:

Or you can do that. I assume you are doing this for SEO purposes?
0
rascalAuthor Commented:
Thanks Jason,
And yes, this is for SEO purposes.
0
Jason C. LevineNo oneCommented:
Just be a little careful with implementation, then.  The workaround works but WordPress will report a different link slug than what Google is expecting to see and this might (emphasis on might) trigger a spam penalty.  It shouldn't, but I would keep a close eye on GWT and Analytics.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.