I want to redirect the home of my old site to the home of my new site, while I want every subpage to redirect to the page search of the new site.
Briefly:
www.oldsite.it --> http://newsite.it
and
www.oldsite.it/whatever --> http://newsite.it/search?q=whatever
I want the conditions to live both and strictly.
I achieved to let them work but separately.
Here's my code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} oldsite\.it/$
RewriteRule ^(.*)$ http://newsite.it/search?q=$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
How can I make them work?
Thanks
You need 2 conditional rules here to redirect the old homepage and old urls to the new location ,try :
RewriteEngine On
RewriteBase /
#1)redirect "oldsite.it" to "newsite.it#
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.it$
RewriteRule ^$ http://newsite.it [NC,L,R]
#2)redirect "oldsite.it/foobar" to "newsite.it/search?q=foobar#
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.it$
RewriteRule ^(.+)$ http://newsite.it/search?q=$1 [QSA,NC,R,L]
Clear your browser's cache before testing these rules.
To make the redirect permanent ,change R to R=301 in both rules when you are sure the rules are working.
Related
I have a wordpress site, the url was www.mysite.com/name-of-the-post
But the client change to www.mysite.com/blog/name-of-the-post
Now I have a problem with the users who click on old links, they can't access the content.
How can I solve this? I've reading about and something with regular expressions on htaccess, how can I add "/blog" when the users trying to access old links?
Thanks guys
Where I will put this code? My htaccess is this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
We recently moved from a Clover site to a Wordpress site so the structure on our podcasts has changed. We have two podcast feeds, one for audio, and one for video.
The old podcast feeds were pulling in from these urls...
http://nmconline.net/podcast.php?pageID=27
http://nmconline.net/podcast.php?pageID=28
Our new feeds are sitting at...
http://nmc.church/feed/videopodcast
http://nmc.church/feed/audiopodcast
I've tried the redirect a few different ways but still no luck. I've tried using a straight 301 redirect and just recently move to a RewriteRule, but still won't work. Not sure if its important or not, but I am forwarding the old nmconline.net domain to our new nmc.church domain.
Here is my current .htaccess file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^podcast\.php?pageID=27 http://nmc.church/feed/videopodcast [R=301,L]
RewriteRule ^podcast\.php?pageID=28 http://nmc.church/feed/audiopodcast [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thanks in advance!
You cannot match QUERY_STRING in a RewriteRule. Here is how you can do:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^pageID=27$ [NC]
RewriteRule ^podcast\.php$ http://nmc.church/feed/videopodcast? [R=301,L]
RewriteCond %{QUERY_STRING} ^pageID=28$ [NC]
RewriteRule ^podcast\.php$ http://nmc.church/feed/audiopodcast? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
? at the end of URL will remove previous query string.
I'm moving a site from static html to the wordpress platform and trying to set up redirects but I can't seem to get it working. The site is at http://slysmidtown.com
What I would like to do is redirect requests for menu.html to /menu/
and redirect all other .html file requests to index.php or just http://slysmidtown.com
this is what I have so far the top line almost works so that the site will load but still requests the html file the rest is written by wordpress
RewriteEngine on
rewriterule ^menu.html(.*)$ http://slysmidtown.com/menu/$1 [r=301,nc]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You forgot that you need to rewrite it back internally to a file, since Apache doesn't know how to handle /menu/ urls now. To prevent infinite redirects you need to let the redirect only match on an external request:
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /menu\.html\ HTTP
RewriteRule ^ /menu/ [R,L]
RewriteRule ^menu/?$ /menu.html [L]
You had the rule in the wrong place, placing it just after the rewritebase should work/:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Rewriterule ^menu.html(.*)$ http://slysmidtown.com/menu/$1 [r=301,nc]
Rewriterule ^(.*).html(.*)$ http://slysmidtown.com/ [r=301,nc]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have a website and i want to make it always show as www.mysite .com i put that code in .htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
now the url shows as www but the website is not shown the browser said "This webpage has a redirect loop"
Note: .htcaccess do not have any code but this few lines i wrote
does i did anything wrong or i miss something??? please help
Edit:
before I add the above code the .htaccess had the following code but not direct to www i remove it :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteCond %{QUERY_STRING} ^m=1$
RewriteRule (.*) $1? [R=permanent]
# END WordPress
could that be updated to solve my problem?
if you are doing it at windows server it will not work if it is window you have to create web.config file n for linux it should be .htaccess
Ok so Wordpress is also there. Make sure to do these 2 things:
Put your 301 rule above WP's rules i.e. just below RewriteBase line
Update WP settings to have your site address with www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
or
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
I want that if someone got link to my site, lets say: www.bla.com/index.php , he will redirect to www.bla.com. or in another words - remove the index.php.
Here is my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^bla\.com$ [NC]
RewriteRule ^(.*)$ http://www.bla.com/$1 [L,R=301]
Either if someone got link: www.bla.com/camera/index.php - it will redirect to www.bla.com/camera/.
For now, the site itself works great, without index.php, but i want to remove the index.php if someone came from extern link.
This post is tagged with WordPress. All of what you're looking for and doing (canonical domain, canonical url without index.php) has been built into WordPress at least since WP 3.0 when permalinks are turned on... Look into canonical redirects -- you'll find the logic in there.
try like that in
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^bla\.com$ [NC]
RewriteRule ^(.*)$ http://www.bla.com/$1 [L,R=301]
RewriteRule ^index.php/(.*)$ /$1 [R=302,L]
RewriteRule ^(.*)$ index.php?/$1 [L]
Try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I believe the OP wants to prevent using index.php even when external links are involved. After following the advice from the other question. Try this.
RewriteRule ^(.*)/index.php$ http://www.bla.com/$1/ [L,R=301]