Forum Moderators: phranque

Message Too Old, No Replies

Simple one - RewriteRule

         

strazdinjsh

11:59 am on Aug 2, 2011 (gmt 0)

10+ Year Member



my one line of the code in .htaccess file is as follows:


RewriteRule ^andis-services/web-design/search-engine-optimization/page-([^-]*)\.html$ index.php?m=1&s=3&p=$1 [L]


the link in simple php file looks like:


echo '<a href = "andis-services/web-design/search-engine-optimization/page-100.html">test</a>';



the issue is that link does not target the same page all the time. after every click on it, i am getting redirection to:

2nd click goes to:

andis-services/web-design/search-engine-optimization/andis-services/web-design/search-engine-optimization/page-100.html


3rd click goes to:

andis-services/web-design/search-engine-optimization/andis-services/web-design/search-engine-optimization/andis-services/web-design/search-engine-optimization/page-100.html


etc.


Could anyone have a look on this case and give me some advice on it?

lucy24

6:43 pm on Aug 2, 2011 (gmt 0)

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



I would look first at the php.

Something is quietly changing "index.php" into "andis-services/web-design/search-engine-optimization/" and adding it to the previous result-- and would presumably keep doing it until the cows come home or you get tired of clicking.

If it were an htaccess problem you'd be getting an infinite loop. Fortunately the [^-] prevents this from happening. But what's with the asterisk? Do you ever get requests in the form "page-.html" ?

When does the newly worded address show up? When you first hover over the link, or only after you click and let go? I assume you didn't mean this is literally the only thing in your htaccess. It's just the only thing you're working on.

g1smd

11:14 pm on Aug 2, 2011 (gmt 0)

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



Also, the * allows "zero" characters after the hyphen and before the .html part.

You'll probably want to change the * to be a + instead.

strazdinjsh

7:54 am on Aug 3, 2011 (gmt 0)

10+ Year Member



Just want to clarify some things:

1. this is only example, simplified part of the real index.php

2. example index.php contains only one link in it

echo '<a href = "andis-services/web-design/search-engine-optimization/page-100.html">test</a>';


3. this link refers to the same index.php according .htaccess ModRewrite rule

RewriteRule ^andis-services/web-design/search-engine-optimization/page-([^-]+)\.html$ index.php?m=1&s=3&p=$1 [L]


where

index.php => andis-services
m=1 => web-design
s=3 => search-engine-optimization
p=XX => page-XX


The issue:

- 1st click on the link refers to the path given in .htaccess

- 2nd click goes to the index.php?m=1&s=3/index.php?m=1&s=3&p=$1 or something like that.

- 3rd click goes to the index.php?m=1&s=3/index.php?m=1&s=3/index.php?m=1&s=3&p=$1 or something like that.

P.S. all these clicks i was able to test adding couple of new rules in .htacces file, example,


RewriteRule ^andis-services/web-design/search-engine-optimization/andis-services/web-design/search-engine-optimization/page-([^-]+)\.html$ index.php?m=1&s=3&p=$1 [L]



Preferred result:

link after the click (no matter how many times clicked)
echo '<a href = "andis-services/web-design/search-engine-optimization/page-100.html">test</a>';
still refers to the same page

andis-services/web-design/search-engine-optimization/page-100.html


P.S. i would like to know if possible, why modrewrite rule lets link to behave this way instead of expected result.

lucy24

6:26 pm on Aug 3, 2011 (gmt 0)

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



RewriteRule ^andis-services/web-design/search-engine-optimization/page-([^-]+)\.html$ index.php?m=1&s=3&p=$1 [L]

where

index.php => andis-services
m=1 => web-design
s=3 => search-engine-optimization
p=XX => page-XX

I don't understand what you mean by ==>

Is that what your index.php currently does, or what you want it to do? Or are you trying to make part of the clicked url into a query string?

Preferred result:

link after the click (no matter how many times clicked)echo '<a href = "andis-services/web-design/search-engine-optimization/page-100.html">test</a>'; still refers to the same page


I don't think that's what you meant to say. In real life, where will the link be coming from? Why will the url be different from what you want it to be? If you want it to stay exactly the same, obviously there would be no need for htaccess.

Again, .htaccess cannot change what is actually printed in your <a href...> line, so the result would always be the same. That's why I suggested looking at your php (different forum).