I need some help with setting up the .htaccess file for redirecting old urls to new ones. The difference is the new 'categories' segment. Note that the website has multiple languages. Any help or tips are much appreciated!
old url:
http://www.website.com/en/products/142/accessories-hoses/490/sg-01-manhole-grid-deflection
new url:
http://www.website.com/en/products/categories/142/accessories-hoses/490/sg-01-manhole-grid-deflection
You may use this rule as top rule in your site root .htaccess:
RewriteEngine On
RewriteRule ^(en/products)/(\d+/.+)$ /$1/categories/$2 [L,NC,R=301,NE]
Related
I have used Stackoverflow a lot to find answers to my questions, but this time I can not find an answer. Maybe it is because english is not my native language and therefore I can not find the right query to search.
I have created a .htaccess files for redirects from our current website to our new website on a new domain. The .htaccess file has 266 rules now and it works fine (I have tested several rules and the redirects work fine on a individual level).
Now my question: I would like to create an extra rule that catches all the remaining URL's that are not in the .htaccess file and redirect all of that URL's to the new homepage. These include pages that we will not create on the new domain because they are outdated or pages that we maybe forgot etc.
I have tried several rules like:
RewriteRule ^(.*)$ https://www.newdomain.com/ [L,R=301,NC]
But this redirects all URL's to the new homepage, so it ignores all other rules I have made in de .htaccess file. Even if I put the rule in the end of the file.
I hope you guys can help! tnx in advance!
Pike
this may be not help much, but the "L" Flag tells Apache not to process any more rules if this one is used.
try
RewriteRule ^(.*)$ https://www.newdomain.com/ [R=301,NC]
and more rewrite cheatsheets in here
I'd like to use ReWrite to use SEO friendly urls that point to a dynamic url.
For example:
I want the SEO Friendly URL: www.example.com/1/Bird/
to bring up content from the dynamic URL: www.example.com/painting-details.cfm?ID=1&Type=Bird
This is the ReWrite that I've tried in the .htaccess file with no luck:
RewriteEngine on
RewriteRule /(.*)/(.*)/$ painting-details.cfm?ID=$1&Type=$2
Any help is greatly appreciated.
Just needed to get rid of the first slash. .htaccess should read:
RewriteEngine on
RewriteRule (.*)/(.*)/$ painting-details.cfm?ID=$1&Type=$2
I've been looking to find a solution for this problem but I believe I'm not asking the right question so I'll explain it in detail here.
I built a new HTML site and I want to redirect the old domain which was a PHP site to the new domain which is going to be a HTML site. URL structure is same but file format is changed.
I need a .htaccess code that redirects all pages from old domain to pages of the new domain.
for example: oldsite.com/contact.php ===> newsite.com/contact.html
any ideas?
thanks
Try adding this rule to the htaccess file in your oldsite.com's document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} oldsite\.com$ [NC]
RewriteRule ^(.*)\.php$ http://newsite.com/$1.html [L,R=301]
I've made a huge mistake in my shop when creating pagination links. After the .html, instead of a question mark my code just appended an ampersand. Now Google Webmaster tools is throwing up hundreds of 404's.
I know how to fix the problem on a URL by URL basis, but is there a wildcard solution as a first off sanity check in HTAccess to check for ".html&" and replace with ".html?"?
Below are examples of my issue, myitemspage represents a category of items, so i have over 50 categories:
http://www.domain.com/myitemspage.html&page=1&limitchange=10
http://www.domain.com/myitemspage.html&page=1&limitchange=25
http://www.domain.com/myitemspage.html&page=1&limitchange=50
http://www.domain.com/myitemspage.html&page=1&limitchange=100
Thank you for any help on my self-created nightmare,
Mark.
Try:
RedirectMatch 301 ^(.*)\.html&(.*)$ /$1.html?$2
or using mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.html&(.*)$ /$1.html?$2 [L,R=301]
in the htaccess file in your document root.
Previously I have vbulletin forum installed on main domain. Now I have replaced it with WP blog and shifted forum to subfolder. Both WP and vB has seperate htaccess files. Please help me to redirect old forum urls to new ones.
Old url pattern:
www.domain.com/f1/post-title/
www.domain.com/f2/post-title/
www.domain.com/f3/post-title/
New url pattern:
www.domain.com/forums/f1/post-title/
www.domain.com/forums/f2/post-title/
www.domain.com/forums/f3/post-title/
Please somebody help me with rewriting rules for correct redirection. Also mention which htaccess (WP or vB) to put the code. Thanks in advance.
It needs to be placed on the .htaccess on the root folder of your domain.
So if your root folder is /home/youraccount/public_html/ then in the .htaccess in that folder.
This will redirect as you asked above, any forum/topic to forums/forum/topic
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^(f\d+)/([^/]+)/?$ /forums/$1/$2/ [R=301,L]
I could use ([^/]+) twice but since you mentioned you have a WordPress in the root now then you should need a more specific rule for the first folder like the above.
This will match the forum id aka f1, f2 ... up to any amount of numbers:
(f\d+)
This will get anything not a / so it will get the post id and title altogether.
([^/]+)
If you have more rules inside your .htaccess file make sure you place this rule after RewriteEngine on and before any other rule, so it doesn't conflict with other rules and redirect as you asked:
RewriteRule ^(f\d+)/([^/]+)/?$ /forums/$1/$2/ [R=301,L]