How would I do this 301 redirect in my htaccess file?
OLD URLs
http://www.domain.com/newsletter/modules.php?op=modload&name=News&file=article&sid=221
http://www.domain.com/newsletter/modules.php?op=modload&name=News&file=article&sid=224
NEW URLs
For 221 - https://www.domain.com/news/
For 224 - https://www.domain.com/treatments/laser-comb/iso-certification/
Explanation: Basically everything is the same in the OLD urls except for the article ID number at the end.
At the top of your htaccess file, add the following :
RewriteEngine on
#1)
RewriteCond %{THE_REQUEST} /newsletter/modules\.php\?op=modload&name=News&file=article&sid=221 [NC]
RewriteRule ^ http://www.domain.com/news/? [L,R=301]
#2)
RewriteCond %{THE_REQUEST} /newsletter/modules\.php\?op=modload&name=News&file=article&sid=224 [NC]
RewriteRule ^ https://www.domain.com/treatments/laser-comb/iso-certification/? [L,R=301]
Related
Using this for example:
RewriteEngine On
Rewritecond %{HTTP_HOST} !^www\.hslab\.nl
RewriteRule (.*) http://www.hslab.nl/$1 [R=301,L]
It will add the www part to the url if it is not there.
Why can it not be something other then www, for example wwwwwww?
When I do that I get a 404.
Based on your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
##Rule when www is present in URL so add only www to url.
Rewritecond %{HTTP_HOST} ^(www)\.hslab\.nl
RewriteRule ^ http://%1%1.hslab.nl%{REQUEST_URI} [NE,R=301,L]
##Rule when www is NOT present in URL, hence add wwwwww to url as per OP
Rewritecond %{HTTP_HOST} !^www\.hslab\.nl
RewriteRule ^ http://wwwwww.hslab.nl%{REQUEST_URI} [NE,R=301,L]
I am on a wordpress multisite.
I have old urls with the same subfolder name now i have to redirect old url to a new url with new subfolder name.
Example (will be simpler)
Old url 1 to new url 1:
http://site1.fr/fr-chauffage.html to
https://www.site1.fr/installation_chauffage
Old url 2 to new url 2:
http://site2.fr/fr-chauffage.html to https://www.site2.fr/installateur_chauffage_dans_ma_region
So I wrote the following htaccess file
RewriteCond %{HTTP_HOST} ^site1\.fr
RewriteRule ^/?(.*)$ https://www.site1.fr/$1 [R=301,L]
RewriteRule ^fr\.html$ / [R=301,L]
RewriteRule ^fr-chauffage.html$ /installation_chauffage/ [R=301,NC,L]
RewriteCond %{HTTP_HOST} ^site2\.fr
RewriteRule ^/?(.*)$ https://www.site2.fr/$1 [R=301,L]
RewriteRule ^fr\.html$ / [R=301,L]
RewriteRule ^fr-chauffage.html$ /installateur_chauffage_dans_ma_region/ [R=301,NC,L]
The trouble is whatever the website the user is always redirect to site1 + good_subfolder
If I have 3 websites with the same subfolder name the user will be always redirected to site1 + good_subfolder of the new url ...
The trouble is whatever the website the user is always redirect to site1 + good_subfolder
Because the RewriteCond directive only applies to the first RewriteRule that follows. The two subsequent RewriteRule directives are executing unconditionally.
You need to repeat the condition for all rules where it needs to apply.
You're directives are also in the wrong order - you need to have the more specific rules first, otherwise you will get multiple redirects. Currently, you are redirecting everything in your first rule. And then you have a more specific redirect later.
So, are all incoming requests less the www prefix (as suggested in your examples and directives)?
Try the following instead:
# Common rules for both sites
# (Although this will result in 2 redirects if requesting the non-canonical hostname)
RewriteRule ^fr\.html$ / [R=301,L]
# Site 1 rdirects
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.fr [NC]
RewriteRule ^fr-chauffage.html$ https://www.site1.fr/installation_chauffage/ [R=301,NC,L]
# Site 2 rdirects
RewriteCond %{HTTP_HOST} ^(www\.)?site2\.fr [NC]
RewriteRule ^fr-chauffage.html$ https://www.site2.fr/installateur_chauffage_dans_ma_region/ [R=301,NC,L]
# non-www to www redirect - both sites
RewriteCond %{HTTP_HOST} ^(site1\.fr|site2\.fr) [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301,L]
I want to redirect below two dynamic url from old url's to new url's using .htaccess and i have done this application using codeigniter.
1) This are the dynamic url's and there are more than thousands of url's in my database.
Old(From) URL
https://www.example.com/area-name/pangothe-263001
New(To) URL
https://www.example.com/pangothe-263001
2) This are the amp version of the above url.
Old(From) URL
https://www.example.com/amp-area-name/pangothe-263001
New(To) URL
https://www.example.com/pangothe-263001/amp
I have tried with below code
RewriteRule ^area-name$ http://www.example.com/area-name [R=301,L]
RewriteRule ^amp-area-name$ http://www.example.com/amp-area-name [R=301,L]
But not redirecting to the new urls. How can do this redirect using .htaccess.
Keep these 2 redirect rules just below RewriteEngine line:
RewriteEngine On
RewriteRule ^area-name/(.+)$ /$1 [R=301,L,NC,NE]
RewriteRule ^amp-area-name/(.+)$ /$1/amp [R=301,L,NC,NE]
# remaining rules go below this
Try This
RewriteRule ^area-name/pangothe-263001/?$ $1/pangothe-263001$2 [R=301,L]
Try with below rules,
Canonical links Redirect
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/area-name/(.*)$
AMP links Redirect
RewriteRule ^ https://www.example.com/%1 [R=301]
RewriteCond %{REQUEST_URI} ^/amp-area-name/(.*)$
RewriteRule ^ https://www.example.com/%1/amp [R=301]
I am making a mini blog that could make it's url looks like this:
From: http://127.0.0.1/index.php?post=the-story-of-us
To: http://127.0.0.1/view/the-story-of-us
I have tried this but i'm getting 404 not found.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?post=([^&]+)
RewriteRule ^ /view/%2/? [L,R=301]
Your current rule only handles the case: Redirect old url to new url.
(By the way, +1 for using THE_REQUEST to avoid a redirect loop)
You also need to handle the case: Rewrite (internally) new url to old url.
Here is how your htaccess should look like
RewriteEngine On
# Redirect /index.php?post=XXX to /view/XXX
RewriteCond %{THE_REQUEST} \s/index\.php\?post=([^&\s]+)\s [NC]
RewriteRule ^ /view/%1? [L,R=301]
# Internally rewrite back /view/XXX to /index.php?post=XXX
RewriteRule ^view/([^/]+)$ /index.php?post=$1 [L]
I do not udnerstand your RewriteCondition, but the RewriteRule should look like this:
RewriteEngine on
RewriteBase /
RewriteRule ^view/(.*)/? ./index.php?post=$1 [L,R=301]
my htaccess file has these lines:
RewriteRule ^newlink ?do=something
Redirect 301 /oldlink/ /newlink
when i write http://www.example.com/oldlink/, browser redirects to http://www.example.com/newlink?do=something
how can i trim ?do=something ??
it should redirect to /newlink; not /newlink?do=something
Don't mix mod_rewrite rules with mod_alias ones. Keep your rules using mod_rewrite itself like this:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+newlink[\s?] [NC]
RewriteRule ^ /?do=something [L,NC,QSA]
RewriteCond %{THE_REQUEST} \s/+oldlink/?[\s?] [NC]
RewriteRule ^ /newlink? [L,NC,R=302]
? in the end is for trimming any existing query string.