Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   SOLVED!!!! WordPress Rewrite Rule (https://www.warriorforum.com/programming/377237-solved-wordpress-rewrite-rule.html)

xtrapunch 8th May 2011 07:17 AM

SOLVED!!!! WordPress Rewrite Rule
 
I need to rewrite the following URL

Example.com/hot-presidents.php?celeb=obama&val=big-fan

into

example.com/obama-hot-presidents/

I am trying to do this in WordPress with the following code.

#WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^([A-Za-z0-9]+)-hot-presidents/$ hot-presidents.php?celeb=$1&val=big-fan [L]
</IfModule>

What am I doing wrong?

ToneUK 8th May 2011 09:09 AM

Re: Help!!!! WordPress Rewrite Rule
 
looks like you are missing a forward slash from before the hot-presidents.php.

Try this:

Code:

RewriteRule ^([A-Za-z0-9]+)-hot-presidents/$ /hot-presidents.php?celeb=$1&val=big-fan [L]

ToneUK 8th May 2011 09:17 AM

Re: Help!!!! WordPress Rewrite Rule
 
Oh, and try putting it above the following line:

RewriteRule ^index\.php$ - [L]

I think this rule is interfering with it.

Christian Little 8th May 2011 10:15 AM

Re: Help!!!! WordPress Rewrite Rule
 
You shouldn't be touching the .htaccess file AT ALL.

Login to Wordpress, click on Settings -> Permalinks.

Set it to use a custom permalink structure that looks like:

/%category%/%postname%

Click save.

Fixed.

xtrapunch 8th May 2011 12:00 PM

Re: Help!!!! WordPress Rewrite Rule
 
Quote:

Originally Posted by ZeusArticles (Post 3846555)
Oh, and try putting it above the following line:

RewriteRule ^index.php$ - [L]

I think this rule is interfering with it.

Thanks a tonne. Moving the rule up solved the problem. I had been struggling with it for an hour.

ToneUK 8th May 2011 12:06 PM

Re: Help!!!! WordPress Rewrite Rule
 
Haha, no problem, I know the feeling.

SteveJohnson 8th May 2011 02:10 PM

Re: Help!!!! WordPress Rewrite Rule
 
Quote:

Originally Posted by Christian Little (Post 3846808)
You shouldn't be touching the .htaccess file AT ALL.

Login to Wordpress, click on Settings -> Permalinks.

Set it to use a custom permalink structure that looks like:

/%category%/%postname%

Click save.

Fixed.

Don't know why you'd say that - there are a lot of reasons that more advanced users would have to modify the .htaccess file.

The OP is a case in point. Your solution wouldn't work, WP would just throw a 404.

The permalink structure you suggest shouldn't be used, especially if you expect to use more than a few pages (not posts) on your site. The number of entries in the rewrite table grows exponentially when a non-numeric first section is used.

While it may not LOOK as good, a better structure is
Code:

/%post_id%/%postname%/
A permalink structure like that cuts the size of the lookup table substantially, and helps speed up your WP site.

xtrapunch 8th May 2011 03:15 PM

Re: Help!!!! WordPress Rewrite Rule
 
Quote:

Originally Posted by Christian Little (Post 3846808)
You shouldn't be touching the .htaccess file AT ALL.

Sometimes you need more than what WordPress offers. It's only for more sophisticated sites, not for regular users.

xtrapunch 8th May 2011 03:20 PM

Re: Help!!!! WordPress Rewrite Rule
 
Quote:

Originally Posted by SteveJohnson (Post 3847739)
Don't know why you'd say that - there are a lot of reasons that more advanced users would have to modify the .htaccess file.

The OP is a case in point. Your solution wouldn't work, WP would just throw a 404.

The permalink structure you suggest shouldn't be used, especially if you expect to use more than a few pages (not posts) on your site. The number of entries in the rewrite table grows exponentially when a non-numeric first section is used.

While it may not LOOK as good, a better structure is
Code:

/%post_id%/%postname%/
A permalink structure like that cuts the size of the lookup table substantially, and helps speed up your WP site.

The code is working fine now, thanks to another warrior. Was making a silly mistake.

As the rewrite rule is being done for auto-generated content, I can't find a better way than how it is being done.

The website is too complicated to apply rules for general websites and blogs. It fetches different content from other sites based on the URL itself.

g36 8th May 2011 04:53 PM

Re: SOLVED!!!! WordPress Rewrite Rule
 
Why not touching .htaccess? It can be very useful to modify .htaccess file such as cloaking affiliate/referral link.


All times are GMT -6. The time now is 12:01 PM.