Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule Link Problem

unnecessary directory in the path...

         

nbozic

12:03 am on Dec 19, 2003 (gmt 0)

10+ Year Member



I have yet another problem with using the rewrite rules.

This is my rewrite rule:
RewriteRule ^category([0-9]*)/index\.html$ index.php?c=$1 [L]

It converts this:
[mydomain.com...]
into this:
[mydomain.com...]

The first page contains links like this: [mydomain.com...]
... which are processed by the rewrite rule once they are clicked.

Unfortunately the destination page inherits links like this:
[mydomain.com...]

Instead of:
[mydomain.com...]

Basically, "category1" gets stuffed in every URL although I don't intend for it to be that way. This gives me "not found" errors everywhere.

Any ideas on how to fix it? What kind of rewrite rule should I add to htaccess file to correct the problem?

jdMorgan

3:12 am on Dec 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See the RewriteBase [httpd.apache.org] directive - that may be what you need.

Jim

nbozic

4:19 am on Dec 19, 2003 (gmt 0)

10+ Year Member



Thanks. I'll give it a shot.

nbozic

4:36 am on Dec 19, 2003 (gmt 0)

10+ Year Member



Well, I don't seem to be able to get it to work...

nbozic

5:59 am on Dec 19, 2003 (gmt 0)

10+ Year Member



... when I add "RewriteBase /forum" to the htaccess file, it doesn't change anything - I still get the same problem.

jdMorgan

8:23 am on Dec 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might try:

RewriteBase /category1
or
RewriteBase /category2

depending on where your .htaccess file with the rewrite is located.

That may not do it. If not, re-post your directory layout, your .htaccess location, your .htaccess rules, and specify the exact file locations relative to web root and the format of the links they contain -- This all gets a bit confusing since we're not familiar with your directory/URL layout and can't look over your shoulder.

Also, some rewriterules may effect others, and sometimes the way to prevent it is to add more rules. Other times it is to add exclusions to existing rules.

Jim

nbozic

2:11 pm on Dec 19, 2003 (gmt 0)

10+ Year Member



jdMorgan,

I had the same issue with images on the destination page - now the difference is that the problem is with the links on the same destination page.

To solve the image problem you gave me the RewriteRule suggestion ^category1/images/(.*)$ /forum/images/$1 [L].
This prevented the images from being searched in the forum/category1/images/ directory. Instead it searched in the forum/images/ directory and produced the right outcome.

The same problem persists with the links, because they are also relative: href="category2/page.html". When the address bar says .../category1/index.html, the "category2/page.html" relative link gets appended to form .../category1/category2/page.html instead of just .../category2/page.html. I plan to make all links absolute, but I'm still wondering if there is a way, the same as for the images, to solve the link problem using RewriteRule.

Thanks.

By the way, my htaccess file is in the forum/ directory.

jdMorgan

5:39 pm on Dec 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule ^category1/category2/(.*)$ /category2/$1 [L]
or for all categories:
RewriteRule ^category[0-9]/category([0-9])/(.*)$ /category$1/$2 [L]

Jim

This thread refers to a previous thread at: [webmasterworld.com...]

nbozic

10:38 pm on Dec 19, 2003 (gmt 0)

10+ Year Member



Thank you.