Welcome to WebmasterWorld Guest from 35.173.234.237

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

RewriteRule Link Problem

unnecessary directory in the path...

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


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?

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


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

Jim

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


Thanks. I'll give it a shot.
4:36 am on Dec 19, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


Well, I don't seem to be able to get it to work...
5:59 am on Dec 19, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


... when I add "RewriteBase /forum" to the htaccess file, it doesn't change anything - I still get the same problem.
8:23 am on Dec 19, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


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

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


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.

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


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...]

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


Thank you.