Results 1 to 7 of 7

Thread: mod_rewrite usage

  1. #1
    Future AstonMartin driver r2d2's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,608

    mod_rewrite usage

    Hi all, I'm getting frustrated trying to integrate WordPress, does anyone know how to use mod_rewrite to change:

    Code:
    /section1/article_name.html
    to

    Code:
    /section1/article_name/
    so that WordPress can understand it? I have changed the custom permalinks setting to use .html, but it still doesnt recognise it and I get a 404...

  2. #2
    Future AstonMartin driver r2d2's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,608
    I should perhaps say that this is in order to retain existing URLs, and I have tried various things like:

    Code:
    RewriteRule ^([a-zA-Z-_]*)\.html$ $1/

  3. #3
    King of da Wackos Nintendo's Avatar
    Join Date
    Oct 2004
    Location
    Planet Zeekois
    Posts
    166
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^section1/([^.]+)/$ section1/$1.html [L]

    (If /section1/article_name.html is the original URL.)

    RewriteRule ^section1/([^.]+)\.html$ section1/$1/ [L]

    (If /section1/article_name/ is the original URL.)

    If there's an original .php URL in this, then it won't work due to the infinite loop.

  4. #4
    Future AstonMartin driver r2d2's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,608
    Aha, the King of mod_rewrite!

    Your version does rewrite the URL now, but unfortunately, I don't think WordPress is understanding it.

    I have this other line in there (created by WordPress):

    RewriteRule . /index.php [L]

    Do you know exactly what this is doing? Redirecting everything to index.php?

  5. #5
    King of da Wackos Nintendo's Avatar
    Join Date
    Oct 2004
    Location
    Planet Zeekois
    Posts
    166
    Yep. Just as I guessed. There's also the original php URL. It goes bonkers if you have code for one URL, then try to change the URL.

    It would need to be something like

    RewriteRule ^section1/([^.]+)/$ index.php?something=$1 [L]

    Original URL, to new URL. Even just adding a 404 redirect from the old mod_rewrite URL to new URL wouldn't work, since there would be the original URL, plus two fake URLs.

    Is

    RewriteRule . /index.php [L]

    the only thing you have there? There should be more than that!!! My WordPress blog has 43 index.php RewriteRule lines!! With stuff like
    RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
    RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
    RewriteRule ^page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L]
    RewriteRule ^comments/page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L]
    RewriteRule ^search/(.+)/?$ /index.php?s=$1 [QSA,L]
    RewriteRule ^archives/([0-9]+)(/[0-9]+)?/?$ /index.php?p=$1&page=$2 [QSA,L]
    RewriteRule ^category/([^/]+)/$ /index.php?category_name=$1 [QSA,L]
    RewriteRule ^author/([^/]+)/?$ /index.php?author_name=$1 [QSA,L]
    RewriteRule ^([0-9]{4})/page/?([0-9]{1,})/?$ /index.php?year=$1&paged=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/?$ /index.php?year=$1 [QSA,L]
    If you chmod the .htaccess file to 777 you can use
    wp-admin/options-permalink.php
    to make the .htaccess code. Then change the permission back.

  6. #6
    King of da Wackos Nintendo's Avatar
    Join Date
    Oct 2004
    Location
    Planet Zeekois
    Posts
    166
    hmmm...post your original .php URL of the article_name. I think it might be possible to have a 301 redirect to change one re-write URL to a new one!! I just tested it out, and it's working for me now!!

    Example...
    Code:
    RewriteRule ^([^.]+)/([^.]+)\.shtml$ cgi-bin/amazon_products_feed.cgi?Operation=ItemLookup&ItemId=$1 [L]
    RewriteRule ^([^.]+)/([^.]+)\.html$ http://www.cmgscc.com/$1/$2.shtml [R=301,L]
    from .html to .shtml!

  7. #7
    Future AstonMartin driver r2d2's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,608
    Well, this is what WP created for me, after I gave it the custom permalink URL using .html:

    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    And it didnt work using the .html. I have spent far to long on this, so I am going to use

    Code:
    RedirectMatch permanent ^/([^.]+).html$ http://www.domain.com/$1/
    Then WP can handle the 301'ed URL. Thanks for your suggestions Nintendo.

Similar Threads

  1. Improve Bandwith Usage, Tips
    By Emancipator in forum Website Programming & Databases
    Replies: 40
    Last Post: 11-09-2004, 10:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •