Forum Moderators: phranque

Message Too Old, No Replies

Rewrite for search engine friendly urls

Why do I have to take the wordpress Rewrite rules out for mine to work?

         

jelv

2:14 pm on Apr 25, 2008 (gmt 0)

10+ Year Member



My website uses WordPress. I have added to the htaccess file a rule that allows me to display "product/1234/" instead of "product.php?sku=1234". The part that I added works perfectly only if I get rid of all the wordpress stuff in the htaccess (which obviously I need there for the wordpress driven site to work correctly). With both the wordpress part and my part in the htaccess file, my part doesn't work. What am I doing wrong? It's probably something dumb as this is my first attempt ever at an htaccess file. Here is what I have:

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

# END WordPress

RewriteEngine On
RewriteRule ^product/([0-9]+)/$ /product.php?sku=$1

harjitsinghubhi

2:31 pm on Apr 25, 2008 (gmt 0)

10+ Year Member



Hi,

I think you can straight away use the default option available in wordpress admin panel under Options>Permalinks
You will see 4 options

1 Default
2 Date and Name based
3 Numeric
4 Custom, specify below

In your case you can choose either of them ranging from 2 to 4

jelv

2:42 pm on Apr 25, 2008 (gmt 0)

10+ Year Member



Thanks harjitsinghubhi, I should be more clear. I am using permalinks in wordpress, but product.php is a static page not controlled by wordpress. It's a custom script for a dynamic page that I'm using to display all my products.

The part I've added to the htaccess file allows me to use product/1234 in the url but still be able to grab the sku as a GET variable. And as mentioned above, it works beautifully if I take the wordpress stuff out of the htaccess file. But then the rest of the site doesn't work. Any htaccess suggestions or help anyone?

g1smd

7:24 pm on Apr 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Modify the Wordpress stuff so that it doesn't affect certain files or folders, by using a RewriteCond to detect those.

jelv

7:37 pm on Apr 25, 2008 (gmt 0)

10+ Year Member



That sounds like exactly what I need to do. I'm extremely new to htaccess (this is the first one I've ever worked on). How would I do that?

jelv

7:58 pm on Apr 25, 2008 (gmt 0)

10+ Year Member



Here's what I finally found to work thanks to Cybernaut on another forum:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Your code first
RewriteRule ^product/([0-9]+)/$ product.php?sku=$1 [L]

# WordPress start
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# WordPress end
</IfModule>