View Full Version : mod_rewrite usage
Hi all, I'm getting frustrated trying to integrate WordPress, does anyone know how to use mod_rewrite to change:
/section1/article_name.html
to
/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...
I should perhaps say that this is in order to retain existing URLs, and I have tried various things like:
RewriteRule ^([a-zA-Z-_]*)\.html$ $1/
Nintendo
03-22-2006, 06:39 PM
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.
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?
Nintendo
03-23-2006, 04:29 AM
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.
Nintendo
03-23-2006, 04:56 AM
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...
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!
Well, this is what WP created for me, after I gave it the custom permalink URL using .html:
# 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
RedirectMatch permanent ^/([^.]+).html$ http://www.domain.com/$1/
Then WP can handle the 301'ed URL. Thanks for your suggestions Nintendo.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.