I've recently migrated a forum from vBulletin to SMF and I'm having trouble creating a RewriteCond/RewriteRule that converts the URL http://www.fjcc.com.au/showthread.php?t=3133&page=2 to the URL http://fjcc.com.au/forum_fjcc/index.php?topic=3133.0.
The .htaccess file in the root directory looks like this:
RewriteEngine On
# SMF Rewrite rules for vBulletin links after vBSEO removed
RewriteCond %{QUERY_STRING} ^t=([0-9]+)&page=[0-9]+/?$
RewriteRule ^showthread.php$ /forum_fjcc/index.php?topic=%1.0 [L,R=301]
RewriteCond %{QUERY_STRING} ^t=([0-9]+).*&p=([0-9]+)/?$
RewriteRule ^showthread.php$ /forum_fjcc/index.php?topic=%1.msg%2#msg%2 [L,R=301]
RewriteCond %{QUERY_STRING} ^t=([0-9]+)/?$
RewriteRule ^showthread.php$ /forum_fjcc/index.php?topic=%1.0 [L,R=301]
RewriteCond %{QUERY_STRING} ^f=([0-9]+)&page=[0-9]+/?$
RewriteRule ^forumdisplay.php$ /forum_fjcc/index.php?board=%1.0 [L,R=301]
RewriteCond %{QUERY_STRING} ^f=([0-9]+)/?$
RewriteRule ^forumdisplay.php$ /forum_fjcc/index.php?board=%1.0 [L,R=301]
RewriteCond %{QUERY_STRING} ^do=newthread.f=([0-9]+)/?$
RewriteRule ^newthread.php$ /forum_fjcc/index.php?board=%1.0 [L,R=301]
RewriteCond %{QUERY_STRING} ^r=author/([0-9]+)-.*/?$
# SMF Rewrites for cms directory
RewriteRule ^cms/list.php$ /forum_fjcc/index.php?action=profile;u=%1 [L,R=301]
RewriteCond %{QUERY_STRING} ^t=([0-9]+)&page=[0-9]+/?$
# SMF Rewrites for forum directory
RewriteCond %{QUERY_STRING} ^t=([0-9]+)&page=[0-9]+/?$
RewriteRule ^forum/showthread.php$ /forum_fjcc/index.php?topic=%1.0 [L,R=301]
RewriteCond %{QUERY_STRING} ^t=([0-9]+).*&p=([0-9]+)/?$
RewriteRule ^forum/showthread.php$ /forum_fjcc/index.php?topic=%1.msg%2#msg%2 [L,R=301]
RewriteCond %{QUERY_STRING} ^t=([0-9]+)/?$
RewriteRule ^forum/showthread.php$ /forum_fjcc/index.php?topic=%1.0 [L,R=301]
RewriteCond %{QUERY_STRING} ^f=([0-9]+)&page=[0-9]+/?$
RewriteRule ^forum/forumdisplay.php$ /forum_fjcc/index.php?board=%1.0 [L,R=301]
RewriteCond %{QUERY_STRING} ^f=([0-9]+)/?$
RewriteRule ^forum/forumdisplay.php$ /forum_fjcc/index.php?board=%1.0 [L,R=301]
RewriteCond %{QUERY_STRING} ^do=newthread.f=([0-9]+)/?$
RewriteRule ^forum/newthread.php$ /forum_fjcc/index.php?board=%1.0 [L,R=301]
# SMF Rewrite rules for vBulletin links before vBSEO removed
RewriteRule ^f[\d]+/.+-([\d]+).*/index([\d]+).html/?$ /forum_fjcc/index.php?topic=$1.0 [L,R=301]
RewriteRule ^f([\d]+)/index([\d]+).html/?$ /forum_fjcc/index.php?board=$1.0 [L,R=301]
RewriteRule ^f[\d]+/.+-([\d]+)-post([\d]+)/?$ /forum_fjcc/index.php?topic=$1.msg$2#msg$2 [L,R=301]
RewriteRule ^f[\d]+/.+-([\d]+).*/?$ /forum_fjcc/index.php?topic=$1.0 [L,R=301]
RewriteRule ^f([\d]+)/?$ /forum_fjcc/index.php?board=$1.0 [L,R=301]
RewriteRule ^archive/index.php/t-([\d]+).*html/?$ /forum_fjcc/archive2.php?topic=$1.0 [L,R=301]
RewriteRule ^archive/index.php/f-([\d]+).*html/?$ /forum_fjcc/archive2.php?board=$1.0 [L,R=301]
RewriteRule ^archive/index.php/?$ /forum_fjcc/archive2.php [L,R=301]
RewriteRule ^members/([\d]+).html/?$ /forum_fjcc/index.php?action=profile;u=$1 [L,R=301]
Redirect 301 /index.php /forum_fjcc/
Redirect 301 /forum/showthread.php /forum_fjcc/index.php
Redirect 301 /showthread.php /forum_fjcc/index.php
Redirect 301 /blog/entry.php /forum_fjcc/index.php
Redirect 301 /entry.php /forum_fjcc/index.php
Redirect 301 /blog/blog.php /forum_fjcc/index.php
Redirect 301 /blog.php /forum_fjcc/index.php
Redirect 301 /cms/content.php /forum_fjcc/index.php
Redirect 301 /forum/ /forum_fjcc/index.php
According to the MWL htaccess Tester the rules should return the URL I listed above but that isn't happening - I'm getting /forum_fjcc/index.php?t=3133&page=2 (prefixed by the website URL) instead.
I've been working on this issue for more than a week and I've tried every RewriteCond/RewriteRule combination I've found without any success - hoping someone can point me in the right direction.
I finally sorted this out for myself (and successfully consolidated a few RewriteCond/RewriteRule sets in the process)
The problem was the 'Redirect 301 /showthread.php /forum_fjcc/index.php' statement (although I don't understand why because the statement to rewrite the URL occurred earlier in the file and had the flags [L,R=301] at the end).
My working .htacecss file now looks like this:
# SMF rewrites for vBulletin after vBSEO removed (including forum directory)
RewriteCond %{QUERY_STRING} ^t=([0-9]+)&page=[0-9]+&p=([0-9]+)#[0-9]+(.*)?/?$ [OR]
RewriteCond %{QUERY_STRING} ^t=([0-9]+)&page=[0-9]+&p=([0-9]+)(.*)?/?$
RewriteRule ^(forum)?/?showthread.php$ /forum_fjcc/index.php?topic=%1.msg%2#msg%2 [L,R=301]
RewriteCond %{QUERY_STRING} ^t=([0-9]+)&page=[0-9]+(.*)?/?$ [OR]
RewriteCond %{QUERY_STRING} ^t=([0-9]+)(.*)?/?$
RewriteRule ^(forum)?/?showthread.php$ /forum_fjcc/index.php?topic=%1.0 [L,R=301]
RewriteCond %{QUERY_STRING} ^f=([0-9]+)&page=[0-9]+(.*)?/?$ [OR]
RewriteCond %{QUERY_STRING} ^f=([0-9]+)(.*)?/?$
RewriteRule ^(forum)?/?forumdisplay.php$ /forum_fjcc/index.php?board=%1.0 [L,R=301]
RewriteCond %{QUERY_STRING} ^do=newthread.f=([0-9]+)(.*)?/?$
RewriteRule ^(forum)?/?newthread.php$ /forum_fjcc/index.php?board=%1.0 [L,R=301]
# SMF rewrites for vBulletin before vBSEO removed
RewriteRule ^f[\d]+/.+-([\d]+).*/index([\d]+).html/?$ /forum_fjcc/index.php?topic=$1.0? [L,R=301]
RewriteRule ^f([\d]+)/index([\d]+).html/?$ /forum_fjcc/index.php?board=$1.0? [L,R=301]
RewriteRule ^f[\d]+/.+-([\d]+)-post([\d]+)/?$ /forum_fjcc/index.php?topic=$1.msg$2#msg$2? [L,R=301]
RewriteRule ^f[\d]+/.+-([\d]+).*/?$ /forum_fjcc/index.php?topic=$1.0? [L,R=301]
RewriteRule ^f([\d]+)/?$ /forum_fjcc/index.php?board=$1.0? [L,R=301]
RewriteRule ^archive/index.php/t-([\d]+).*html/?$ /forum_fjcc/archive2.php?topic=$1.0? [L,R=301]
RewriteRule ^archive/index.php/f-([\d]+).*html/?$ /forum_fjcc/archive2.php?board=$1.0? [L,R=301]
RewriteRule ^archive/index.php/?$ /forum_fjcc/archive2.php? [L,R=301]
RewriteRule ^members/([\d]+).html/?$ /forum_fjcc/index.php?action=profile;u=$1? [L,R=301]
# SMF rewrite for cms author
RewriteCond %{QUERY_STRING} ^r=author/([0-9]+)-.*/?$
RewriteRule ^cms/list.php$ /forum_fjcc/index.php?action=profile;u=%1? [L,R=301]
# SMF rewrite for calendar
RewriteRule ^calendar\.php /forum_fjcc/index.php?action=calendar? [L,R=301]
# Other rewrites
Rewrite ^blog\.php /forum_fjcc/index.php? [L,R=301]
Rewrite ^index\.php /forum_fjcc/index.php? [L,R=301]
Rewrite ^entry\.php /forum_fjcc/index.php? [L,R=301]
Rewrite ^showthread\.php /forum_fjcc/index.php? [L,R=301]
Rewrite ^blog/blog\.php /forum_fjcc/index.php? [L,R=301]
Rewrite ^blog/entry\.php /forum_fjcc/index.php? [L,R=301]
Rewrite ^cms/content\.php /forum_fjcc/index.php? [L,R=301]
Rewrite ^forum/ /forum_fjcc/index.php? [L,R=301]
Related
Im trying to redirect several urls with 3 parameters to different static urls with .htaccess but nothing working.
1.
http://olddomain.com/index.php?id_category=28&controller=category&id_lang=2
to
https://newdomain.com/page1/
http://olddomain.com/index.php?id_category=30&controller=category&id_lang=2
to
https://newdomain.com/page2/
http://olddomain.com/index.php
to
https://newdomain.com
I tried the below code but http://olddomain.com/index.php not going to https://newdomain.com :
RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301,NC]
RewriteCond %{QUERY_STRING} ^id_category=28&controller=category&id_lang=2$
RewriteRule ^index.php$ https://newdomain.com/page1/? [R=301,L]
RewriteCond %{QUERY_STRING} ^id_category=30&controller=category&id_lang=2$
RewriteRule ^index.php$ https://newdomain.com/page2/? [R=301,L]
You need to have specific longer matches first and then have rules to remove index.php or domain redirect:
RewriteEngine On
# specific redirects with index.php as optional match
RewriteCond %{QUERY_STRING} ^id_category=28&controller=category&id_lang=2$ [NC]
RewriteRule ^(index\.php)?$ https://newdomain.com/page1/? [R=301,L,NC]
RewriteCond %{QUERY_STRING} ^id_category=30&controller=category&id_lang=2$ [NC]
RewriteRule ^(index\.php)?$ https://newdomain.com/page2/? [R=301,L,NC]
# remove index.php and redirect to newdmain
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteRule ^(?:index\.php/?)?(.*)$ https://newdomain.com/$1 [L,R=301,NC,NE]
Make sure to clear your browser cache before testing this change.
In case you are taking page's id from id_lang= variable then please try following rules. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Rules to redirect to link: https://newdomain.com/page1/ here.
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{THE_REQUEST} \s/index\.php\?id_category=28&controller=category&id_lang=(\d+)\s [NC]
RewriteRule ^ https://newdomain.com/page%1/? [NE,R=301,L]
##Rules to redirect https://newdomain.com/ here.
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{THE_REQUEST} \s/index\.php\s [NC]
RewriteRule ^ https://newdomain.com [NE,R=301,L]
I have this setting for my website for SEO-friendly URL, it's working correct. But when I need set some 301 Redirect it works poorly. When I type in address bar that rule below Redirect 301 /example1 /example2 I get www.domain.com/example2?page=example1. How can I change it?
RewriteEngine on
RewriteRule ^([^/.]+)/?$ index.php?page=$1 [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirect 301 /example1 /example2
You should keep using mod_rewrite since you're already using it. And put the rule above the other one.
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^example/? /example2 [L,R=301]
#redirect to index.php except for example2
RewriteCond %{REQUEST_URI} !^/example2
RewriteRule ^([^/.]+)/?$ index.php?page=$1 [L]
I try to redirect my website from www to no-www for whole content but I don't know how I get it work, because I've got two rewrite rules already.
This is my htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^meaning-first-name\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^([^/\.]+)/?$ index.php?name=$1 [L]
RewriteRule ^([^/\.]+)?$ index.php?name=$1 [L]
RewriteRule ^voorletter/([^/\.]+)/?$ initial.php?letter=$1 [L]
RewriteRule ^voorletter/([^/\.]+)?$ initial.php?letter=$1 [L]
Now is working:
website.com/John* shows: *index.php?name=John
website.com/initial/J* shows: *initial.php?letter=J
But how can I include redirect for www to non-www to this?
Remove the 2 conditions on top and add this instead:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]
Original url: example.com?file=gallery&d=doc
I want: example.com/gallery.html
My .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteRule ^([^/]*)\.html$ /?file=$1&d=doc [L]
(removed d=doc from url because this not needed)
Now clean URL's work but I want 301 redirect all old URL's (?file=example&d=doc). Anyone can help me with .htaccces? Now page is availiable from example.com?file=gallery&d=doc and example.com/gallery.html but should be ONLY from example.com/gallery.html.
Try this :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.med-pro.pl$
RewriteRule ^(.*)$ http://med-pro.pl/$1 [R=301,L]
RewriteRule ^([^/]*)\.html$ /?plik=$1&d=doc&r=0 [L]
RewriteCond %{QUERY_STRING} ^plik=([^&]*)&d=doc$
RewriteRule .* %1.html? [L,NC,R=301]
I want the user to be redirected whenever he reaches my subdomain
Here is what is inside my htaccess:
RewriteEngine On
RewriteRule ^http://smale.deals.com/(.*) http://traual.deals.com/$1 [R=301,L]
RewriteRule ^http://deals.com/smale/(.*) http://deals.com/traual/$1 [R=301,L]
But no redirect happens. why?
I also have got this in my root htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} (Android|iPhone|iPod|Blackberry) [NC]
RewriteCond %{REQUEST_URI} !^/mobile [NC]
RewriteRule ^(.*)/?$ mobile/$1 [L]
You cannot include the protocol and domain in RewriteRule. Those need to be accounted for in RewriteCond:
RewriteEngine On
# Rewrite requests to smale.deals.com to traual.deals.com
RewriteCond %{HTTP_HOST} ^smale\.deals\.com$ [NC]
RewriteRule (.*) http://traual.deals.com/$1 [R=301,L]
# For deals.com...
RewriteCond %{HTTP_HOST} ^deals\.com$ [NC]
# Rewrite requests to smale/ to deals.com/traual/
RewriteRule ^smale/(.*) http://deals.com/traual/$1 [R=301,L]