Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite help please

         

greennature

6:45 am on Nov 10, 2005 (gmt 0)



Please, I'd like to change a batch of 2,500 articles from the string
?module=articles&func=display&ptid=1&aid=#

(where ptid is publication type and it is permanently set to 1 and # stnads for article #s 1-2,500)

to article#.html

anyone have any thoughts?

koen

12:27 am on Nov 11, 2005 (gmt 0)

10+ Year Member



If you change the url pointing to the articles as article#.htm you could use the following rule:

RewriteRule ^article([^/]+).html$?module=articles&func=display&ptid=1&aid=$1

But what comes before the "?"?

greennature

1:41 am on Nov 11, 2005 (gmt 0)



"If you change the url pointing to the articles as article#.htm you could use the following rule:

RewriteRule ^article([^/]+).html$?module=articles&func=display&ptid=1&aid=$1

But what comes before the "?"?"

Sorry, it would be domain.com/

I was refering to the string that comes out when you click on an article link.

Why htm rather than and html extension?

I'm trying to upgrade my site with a new CMS and have to have the exact urls as the current site so as to avoide duplicate content issues.

jdMorgan

8:48 am on Nov 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The point to emphasize here is that you don't change URLs using mod_rewrite -- at least not the way I believe you're thinking of doing it.

The steps typicially go like this:

  • On your site's pages, publish 'search-engine-friendly' URLs.

  • When a friendly URL is subsequently requested from your server (when a client clicks on a friendly-URL link on your page), internally rewrite it to the form needed to call your script (with a query string derived from the friendly URL, etc.)

  • If you receive a direct request from a client using the unfriendly query string-format URL, then externally redirect that request to the friendly URL equivalent. This will 'fix' accidentally-listed unfriendly URLs in search engine listings.

    The second and third step use mod_rewrite. But they aren't useful unless your script does step one. In many cases, this is easy to do, even if the URLs are taken from a database -- You can use the PHP preg_replace function, for example, to convert unfriendly URLs to friendly form while generating a page, and so 'publish' only friendly URLS on your pages.

    It often helps to point out that mod_rewrite processes URLs as they arrive in requests at your server. It works in the URL-to-filepath translation API phase before any content is served and before any scripts are invoked. It has no capability to modify the output content of your pages.

    Jim

  • greennature

    1:19 am on Nov 12, 2005 (gmt 0)



    thanks JD,
    I figured it out.

    The new CMS I'm testing out had a baked in short url that I had to turn off two times at two different places. I also had to omit the first bit of rewrite code in .htaccess that got rid of an index.php the CMS added automatically.

    After all that fuss, my original rewrite worked:)