Forum Moderators: phranque
Basically i am trying to redirect some old wordpress post links to the new ExpressionEngine website posts.
Now I disabled the .htaccess file in the blog folder where wordpress was installed (it was rewriting blog/index.php to blog/) and i have one large .htaccess file in the root.
In that .htaccess the following lines of code that redirect actual .html files work just fine. The link gets redirected and the url gets updated.
RewriteRule ^example-text.html$ http://www.example.com/index.php/category/example-text/ [R=301,L]
Then later on in the same file I use the same technique to redirect the old wordpress blog links:
RewriteRule ^blog/2007/03/example-text/$ http://www.example.com/index.php/blog/example-text/ [R=301,L]
---AND I TRIED ----
RewriteRule ^http://www.example.com/blog/2007/03/example-text/$ http://www.example.com/index.php/blog/example-text/ [R=301,L]
---I ALSO TRIED ---
RewriteRule ^blog/index.php/2007/03/example-text/$ http://www.example.com/index.php/blog/example-text/ [R=301,L]
Can someone please give me a hand, I dont know what is going on.
thanks
Adam
I can tell you that your first and third example rules above are acceptable, syntax-wise, while your second rule won't work except under very specific circumstances (not applicable to your situation).
The local URL-path requested by the browser goes in the pattern on the left, and the URL or URL-path to be substituted goes on the right. If you redirect to a new URL, and that URL matches another rule, then the redirected request will also get redirected or rewritten. So beware of interaction between rules -- This may in fact be why you are not getting the expected results.
To get a better view of the problem, I recommend using the "Live HTTP Headers" add-on for Firefox and Mozilla-based browsers to view the actual HTTP client request and server response headers -- If you are getting multiple redirects, this add-on will show them step-by-step. It's a free but indispensable tool.
Jim
Basically, i previously had wordpress installed in the /blog directory making my links look like website.com/blog/blah/blah/post.
But in reality there is a .htaccess file in the blog directory rewriting /blog/index.php to /blog/ here it is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
so in my new ExpressionEngine site, i have EE installed in the root making my real links website.com/index.php/template/post, but in my root .htacces i have a line of code that removes the index.php if a particular template is requested and "blog" is one of my templates.
AddType application/x-httpd-php .php .html .htm
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [nc]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond $1 ^(site存hop在log圭ommunity在egreen字esources存earch圯mbeds地bout圩eeds地dvertise奸egal同[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
then i have the html rewrites that are working and then i have the blog rewrites as follows:
#rewriting all blog links to new EE links
RewriteRule ^http://www.example.com/blog/2007/03/neutral-existence-project/$ http://www.example.com/index.php/blog/welcome-to-neutral-existence/ [R=301,L]
# Blog categories
RewriteRule ^http://www.example.com/blog/category/bio-fuel/$ http://www.example.com/index.php/blog/biofuel/C7/ [R=301,L]
# Three keywords
RewriteCond %{QUERY_STRING} ^tag=([^\-]+)-([^\-]+)-([^\-]+)$
RewriteRule ^blog/index\.php$ http://www.example.com/index.php/blog/tags/tag/%1+%2+%3? [R=301,L]
# Two keywords
RewriteCond %{QUERY_STRING} ^tag=([^\-]+)-([^\-]+)$
RewriteRule ^blog/index\.php$ http://www.example.com/index.php/blog/tags/tag/%1+%2? [R=301,L]
# One keyword
RewriteCond %{QUERY_STRING} ^tag=([^\-]+)$
RewriteRule ^blog/index\.php$ http://www.example.com/index.php/blog/tags/tag/%1? [R=301,L]
So when i enable the .htaccess file in the blog directory, my old blog comes back online and when i disable it, the links don't work. Any idea how to fix this?
Also, if you rule order is as you say, then you've got problems there as well:
Put your external redirects first, in order from most-specific to least specific, and follow those with your internal rewrites, again in order from most-specific to least-specific. Generally, longest patterns first -- for example, your domain canonicalization redirect should be your last redirect, as it is a 'catch-all' for those URLs with incorrect domain that don't get taken care of by the more-specific preceding rules.
Generally the WordPress rewrites should be the last, since the only requirement to run them is that the requested URL does not resolve to an existing file or directory.
Sorry I can't help more; As noted above, I cannot tell what your real filepaths are and what your 'friendly' URLs are from what is posted.
Jim
Ill try to give you more info here:
<snip>
Here is my .htaccess in the root folder of the site
AddType application/x-httpd-php .php .html .htm
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [nc]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
#rewriting all "green your" html links to new "Be Green" EE links
RewriteRule ^Home-Front.html$ http://www.example.com/index.php/begreen/green-your-home/ [R=301,L]
RewriteRule ^Home-Efficiency-Tax-Breaks-And-Rebates.html$ http://www.example.com/index.php/begreen/home-efficiency-tax-credits-rebates-incentives/ [R=301,L]
#
RewriteRule ^Automobile.html$ http://www.example.com/index.php/begreen/green-your-car-automobile-emissions-and-pollution/ [R=301,L]
RewriteRule ^Efficient-Driving-Habits.html$ http://www.example.com/index.php/begreen/fuel-efficient-driving-habits/ [R=301,L]
#
RewriteRule ^Intoduction-To-Alternative-Energies.html$ http://www.example.com/index.php/begreen/green-your-electricity-alternative-renewable-energy/ [R=301,L]
RewriteRule ^Solar-Power.html$ http://www.example.com/index.php/begreen/solar-power-for-the-home/ [R=301,L]
#
RewriteRule ^Carbon-Offsets.html$ http://www.example.com/index.php/begreen/green-your-travel-with-carbon-offsets/ [R=301,L]
RewriteRule ^Tree-Planting-Offsets.html$ http://www.example.com/index.php/begreen/tree-planting-carbon-offsets/ [R=301,L]
#
RewriteRule ^Green-Building.html$ http://www.example.com/index.php/begreen/green-building-introduction/ [R=301,L]
#
RewriteRule ^Tell-A-Friend.html$ http://www.example.com/index.php/advertise/tell-a-friend/ [R=301,L]
RewriteRule ^Write-A-Congressman.html$ http://www.example.com/index.php/resources/list-of-current-us-representatives/ [R=301,L]
#
#rewriting all blog links to new EE links
RewriteRule ^http://www.example.com/blog/2007/03/neutral-existence-project/$ http://www.example.com/index.php/blog/welcome-to-neutral-existence/ [R=301,L]
RewriteRule ^http://www.example.com/blog/2007/03/environmental-sustainablility-terms/$ http://www.example.com/index.php/blog/carbon-neutrality-sustainability-definitions/ [R=301,L]
#
# Blog categories
RewriteRule ^http://www.example.com/blog/category/bio-fuel/$ http://www.example.com/index.php/blog/biofuel/C7/ [R=301,L]
RewriteRule ^http://www.example.com/blog/category/general/$ http://www.example.com/index.php/blog/general/C9/ [R=301,L]
#
# Three keywords
RewriteCond %{QUERY_STRING} ^tag=([^\-]+)-([^\-]+)-([^\-]+)$
RewriteRule ^blog/index\.php$ http://www.example.com/index.php/blog/tags/tag/%1+%2+%3? [R=301,L]
# Two keywords
RewriteCond %{QUERY_STRING} ^tag=([^\-]+)-([^\-]+)$
RewriteRule ^blog/index\.php$ http://www.example.com/index.php/blog/tags/tag/%1+%2? [R=301,L]
# One keyword
RewriteCond %{QUERY_STRING} ^tag=([^\-]+)$
RewriteRule ^blog/index\.php$ http://www.example.com/index.php/blog/tags/tag/%1? [R=301,L]
#
#
RewriteRule (.*) /index.php?/$1 [L]
#
IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*
#
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName example.com
Wordpress is installed in public_html/blog/ and the .htaccess file in that folder (written by wordpress) which is currently renamed and not working is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
I hope this helps and i appreciate your time. Please let me know if i need to provide you with more information. <snip> [T]he .html redirects work fine, but nothing else does.
[edited by: jdMorgan at 12:25 am (utc) on Feb. 9, 2008]
[edit reason] Edited for length, TOS 24 and 13 [/edit]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [nc]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^http://www.example.com/blog/2007/03/environmental-sustainablility-terms/$ http://www.example.com/blog/carbon-neutrality-sustainability-definitions/ [R=301,L]
RewriteRule ^blog/2007/03/environmental-sustainablility-terms/$ http://www.example.com/blog/carbon-neutrality-sustainability-definitions/ [R=301,L]
Now i have one more little question. how to I make the trailing / not matter? In other words when someone goes to example.com/blog/2007/03/environmental-sustainablility-terms/ they get redirected perfectly, but when someone goes to te same link without that trailing slash:
example.com/blog/2007/03/environmental-sustainablility-terms
they do not get redirected correctly.
How can i fix this easily? without writing new rules for every one.