Forum Moderators: phranque

Message Too Old, No Replies

.htaccess RewriteRule loop

stucked in htaccess puzzle

         

harmeet

1:21 pm on Apr 11, 2009 (gmt 0)

10+ Year Member



Hi all

I am new to htaccess and need to convert some non seo friedly urls into seo friendly urls.

The following htaccess is working but in strange manner :oops:

Options +FollowSymLinks
RewriteEngine on

RewriteRule press_detail/news/(.*)/ press_detail.php?news=$1
RewriteRule press_detail/news/(.*) press_detail.php?news=$1

RewriteRule news_detail/news/(.*)/ news_detail.php?news=$1
RewriteRule news_detail/news/(.*) news_detail.php?news=$1

RewriteRule feature_detail/feature/(.*)/ feature.php?feature=$1
RewriteRule feature_detail/feature/(.*) feature.php?feature=$1

My site is working fine untill i click on link which uses the htaccess rules defined.
After that no link works, every link redirects to one page only.

example:
if i click on www.mydomain.com/press_detail/news/some-news-title
then it works fine, after this, no other link works.

www.mydomain.com/products.php will become www.mydomain.com/press_detail/news/products.php which does not work.

:!:

According to me i did't use RewriteCond directive thats why it is redirecting all urls including those which are not supposed to be redirected. Stil confused :?: what to do as i can't figure out the exect working of RewriteCond. I am playing alot with it but it does't seems to work for me.

Please help me out folks.

Can also anybuddy tell me how to use rewrite.log?

waiting for reply

Harmeet singh

g1smd

6:14 pm on Apr 11, 2009 (gmt 0)

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



Every rule needs [L] at the end of it, otherwise you will get very odd results.

Do not let URLs both with and without a slash invoke the rewrite. That's a Duplicate Content issue. Redirect 'with slash' to 'without slash' with a 301 redirect. Force the correct domain name in the same redirect. Only rewrite for the canonical URL format.

See also: [webmasterworld.com...]

jdMorgan

6:51 pm on Apr 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just a couple of comments:

Because your patterns are not end-anchored, any URL that would match the second rule in each set would already be matched by the first rule. So the second rule in each set above will never be invoked.

Do not use ".*" patterns when you can use a more specific pattern, such as "[^/]+" (meaning, "match one or more characters not equal to a slash") in this case.

if i click on www.mydomain.com/press_detail/news/some-news-title
then it works fine, after this, no other link works.

More details, please. What do you see in the browser when "no other link works"? What do you see in your server *error* log file?

Jim

[edited by: jdMorgan at 7:15 pm (utc) on April 11, 2009]