Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Help: article.php?id=$1&act=$2 to Article/Management/180/index

         

aff_dan

2:09 pm on Dec 7, 2005 (gmt 0)

10+ Year Member



Hello,

I have a problem, please help me:

[RewriteRule ^Article/[^\/]+/([0-9]+)/?(.*) article.php?id=$1&act=$2]

So the url will looks like:
site.com/Article/Management/180

I want to change rewrite rule to show:
anysite.net/Article/Management/180/index.htm

How can I do this?

Regards,
Dan

jdMorgan

2:55 pm on Dec 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your rule is basically correct, although you allow some "optional" fields that you haven't explained.

However, in order for the static URL to "show" you have to publish it. That is, your pages must output the static URLs so that users can click them and 'bots can follow them. When the resulting requests for static URLs arrive at your server, mod_rewrite will change them into the form needed to invoke your article.php script and generate the requested page.

If it's not clear, mod_rewrite modifies incoming URL requests, and has no effect on the content output by your server. It works in the URL-to-filepath translation phase, and not in the content-handling phase.

Making just a few minor tweaks to what you've got, I'd start with:


RewriteRule ^Article/[^/]+/([0-9]+)/? /article.php?id=$1&act=$2 [L]

As with your original, this will accept additional URL-path components after /Article/Management/180 and discard them. There's no need to escape "/" within a negative-match group, and I added the [L] flag so that mod_rewrite will stop processing subsequent rules if this rule matches and the rewrite is invoked.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

aff_dan

4:33 pm on Dec 7, 2005 (gmt 0)

10+ Year Member



Dear Jim,

Thank you very much for your word. This are tested ideas.

I added in .htaccess what you have told me, and the links are site.net/Article/Tomato-Sauce/171

and it is opening with: site.net/Article/Tomato-Sauce/171/index.htm or index.php
This mean google will index. Using thsi rewrite
RewriteRule ^Article/[^/]+/([0-9]+)/? /article.php?id=$1&act=$2 [L]

In the past I got a white blank page without your idea.

Jim, I just few questions:

When I click on the link, I got in browser exactly this address:

site.net/Article/Tomato-Sauce/171

Could I redirect automatically to open link like
site.net/Article/Tomato-Sauce/171/index.html?

Or How could I change the link to be:

site.net/?Tomato-Sauce&id=171

Dan

jdMorgan

7:28 pm on Dec 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, the problem is that you request
example.com/Article/Tomato-Sauce/171/
and the browser redirects to
example.com/Article/Tomato-Sauce/171/index.php?

If this is the case, then you need to look at all .htaccess files and the httpd.conf file in that path, as well as your actual scripts, and find out why that redirect is happening. You cannot fix the redirect by redirecting again, or you will just get a redirect-loop, and the visitor will never see anything but an error page. So, the problem is in your server configuration (.htaccess or httpd.conf) scripts or in your php page-generation scripts.

Once you have fixed the root cause of the problem, you can then 'fix' search engine listings by using an additional redirect. So post whatever you find that is redirecting requests and appending index.xyz to the requested URL.

Jim