Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 8th May 2011, 07:17 AM   #1
WordPress Expert
War Room Member
 
xtrapunch's Avatar
 
Join Date: 2011
Location: New Delhi, India
Posts: 1,097
Thanks: 29
Thanked 172 Times in 131 Posts
Default
SOLVED!!!! WordPress Rewrite Rule
Share on: 
fb share twitter share gplus share more share

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?

>> Web Design, Wordpress & SEO - XtraPunch.com <<
Web Design & SEO Agency | Serving World Wide from New Delhi, India

xtrapunch is offline  
Unread 8th May 2011, 09:09 AM   #2
Active Warrior
War Room Member
 
Join Date: 2011
Posts: 63
Thanks: 4
Thanked 7 Times in 5 Posts
Default
Re: Help!!!! WordPress Rewrite Rule
Share on: 
fb share twitter share gplus share more share

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]

Free article directory for publishers to download. Free article submission with fast approval times. Submit free articles with back links that are Do follow.
ToneUK is offline  
Unread 8th May 2011, 09:17 AM   #3
Active Warrior
War Room Member
 
Join Date: 2011
Posts: 63
Thanks: 4
Thanked 7 Times in 5 Posts
Default
Re: Help!!!! WordPress Rewrite Rule
Share on: 
fb share twitter share gplus share more share

Oh, and try putting it above the following line:

RewriteRule ^index\.php$ - [L]

I think this rule is interfering with it.

Free article directory for publishers to download. Free article submission with fast approval times. Submit free articles with back links that are Do follow.
ToneUK is offline  
Unread 8th May 2011, 10:15 AM   #4
Flying Waffle
War Room Member
 
Join Date: 2011
Location: Vancouver, Canada
Posts: 806
Thanks: 62
Thanked 208 Times in 158 Posts
Default
Re: Help!!!! WordPress Rewrite Rule
Share on: 
fb share twitter share gplus share more share

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.

Christian Little is offline  
The Following User Says Thank You to Christian Little For This Useful Post:
Unread 8th May 2011, 12:00 PM   #5
WordPress Expert
War Room Member
 
xtrapunch's Avatar
 
Join Date: 2011
Location: New Delhi, India
Posts: 1,097
Thanks: 29
Thanked 172 Times in 131 Posts
Default
Re: Help!!!! WordPress Rewrite Rule
Share on: 
fb share twitter share gplus share more share

Originally Posted by ZeusArticles View Post

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.

>> Web Design, Wordpress & SEO - XtraPunch.com <<
Web Design & SEO Agency | Serving World Wide from New Delhi, India

xtrapunch is offline  
Unread 8th May 2011, 12:06 PM   #6
Active Warrior
War Room Member
 
Join Date: 2011
Posts: 63
Thanks: 4
Thanked 7 Times in 5 Posts
Default
Re: Help!!!! WordPress Rewrite Rule
Share on: 
fb share twitter share gplus share more share

Haha, no problem, I know the feeling.

Free article directory for publishers to download. Free article submission with fast approval times. Submit free articles with back links that are Do follow.
ToneUK is offline  
Unread 8th May 2011, 02:10 PM   #7
VIP Warrior
War Room Member
 
SteveJohnson's Avatar
 
Join Date: 2007
Location: Caldwell, Idaho, USA.
Posts: 1,967
Thanks: 1,024
Thanked 2,043 Times in 1,183 Posts
Default
Re: Help!!!! WordPress Rewrite Rule
Share on: 
fb share twitter share gplus share more share

Originally Posted by Christian Little View Post

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.

The 2nd Amendment, 1789 - The Original Homeland Security.

Gun control means never having to say, "I missed you."
SteveJohnson is offline  
The Following User Says Thank You to SteveJohnson For This Useful Post:
Unread 8th May 2011, 03:15 PM   #8
WordPress Expert
War Room Member
 
xtrapunch's Avatar
 
Join Date: 2011
Location: New Delhi, India
Posts: 1,097
Thanks: 29
Thanked 172 Times in 131 Posts
Default
Re: Help!!!! WordPress Rewrite Rule
Share on: 
fb share twitter share gplus share more share

Originally Posted by Christian Little View Post

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.

>> Web Design, Wordpress & SEO - XtraPunch.com <<
Web Design & SEO Agency | Serving World Wide from New Delhi, India

xtrapunch is offline  
Unread 8th May 2011, 03:20 PM   #9
WordPress Expert
War Room Member
 
xtrapunch's Avatar
 
Join Date: 2011
Location: New Delhi, India
Posts: 1,097
Thanks: 29
Thanked 172 Times in 131 Posts
Default
Re: Help!!!! WordPress Rewrite Rule
Share on: 
fb share twitter share gplus share more share

Originally Posted by SteveJohnson View Post

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.

>> Web Design, Wordpress & SEO - XtraPunch.com <<
Web Design & SEO Agency | Serving World Wide from New Delhi, India

xtrapunch is offline  
Unread 8th May 2011, 04:53 PM   #10
g36
:p
 
g36's Avatar
 
Join Date: 2011
Posts: 203
Thanks: 3
Thanked 14 Times in 13 Posts
Default
Re: SOLVED!!!! WordPress Rewrite Rule
Share on: 
fb share twitter share gplus share more share

Why not touching .htaccess? It can be very useful to modify .htaccess file such as cloaking affiliate/referral link.

:)
g36 is offline  
Closed Thread


Bookmarks

Tags
rewrite, rule, wordpress


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 11:40 AM.