I recently installed Prestashop which has URLs in the form of domain.nl/my-account . Now I added a second language which turns URLS into domain.nl/nl/my-account or domain.nl/en/my-account
As people have bookmarked different items and searchengines have indexed the site I would like to redirect visitors to the old URLS (without the language) to be redirected to the same URL with language (NL is preferred).
A redirect to the mainpage is all I could achieve up to this point. Does anyone have an idea how to set this up using .htaccess??
Any help is greatly appreciated.
Try adding this to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(nl|en)/
RewriteRule ^(.*)$ /nl/$1 [L,R=301]
So you may need to change the (nl|en) part, because that regex checks to see if the URL already starts with /nl/ or /en/. You can replace the "en" with whatever other language you don't want redirected.
Related
I would like your help to modify my .htaccess file. My site has been hacked and the malware has created thousands of pages and has really hurt my rankings. I have deleted the pages, but I want all of those links to redirect to one 404 page.
What do I need to write in .htaccess in order to redirect all of the pages that contain a certain word?
I have tried this
RewriteCond %{QUERY_STRING} ^(theword)
RewriteRule ^$ https://example.com/404.php [R=301,L]
But it doesn't seem to work: the 404 page I created appears, but the link still remains in the browser, just that now it's like this
http://example.com/404.php?theword=blablabla
Maybe because my site is on a wordpress platform?
I want all the pages that start with ?theword= to be redirected entirely and for the new link to appear /404.php not /404.php?theword=
Thank you in advance for your help!
The [QSD] (query string discard) flag added to your RewriteRule will drop the query string.
I'm new at programming. We have an office project, the website's URL is www.project.com.ph (sample name), this is already a live website from the client. But the released printouts have the instructions for the users to go to www.project.com/ph which is wrong and we can't reprint the material since it already reached plenty of event places.
Now the problem is, we need to redirect to www.project.com.ph automatically if the users type in the browser's address bar www.project.com/ph. I ask if this is possible without any kind of CMS or Wordpress and how to actually do it? We bought a new domain www.project.com for this. Any kind of help is appreciated.
Try the following near the top of your .htaccess file in the root of www.project.com. This works OK (although marginally less efficient) if both domains are pointing to the same place, since it specifically checks that we are requesting the "wrong" domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?project\.com$ [NC]
RewriteRule ^ph/?(.*) http://www.project.com.ph/$1 [NC,R=302,L]
This will redirect requests for www.project.com/ph (no slash), www.project.com/ph/ (with a trailing slash) and www.project.com/ph/<whatever> to http://www.project.com.ph/<whatever>.
This is a temporary (302) redirect. Change it to a permanent (301) only when you are sure it's working OK.
From kj.'s answer on a similar question, here
In your .htaccess for www.project.com, this should do the trick.
RewriteEngine on
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
This will redirect any request to project.com to the domain http://www.project.com.ph/
To include the path after the /ph/` you can use this.
RewriteEngine on
# redirect including path after ph/ (e.g. project.com/ph/directory/file.php to project.com.ph/directory/file.php
RewriteRule ^ph/(.*)$ http://www.project.com.ph/$1 [R=permanent,NC,L]
# redirect any other requests to project.com.ph index
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
You can redirect (301 redirect) the URL using RewritrRule in .htaccess file
RewriteRule "http://www.project.com/ph/(.*)" "http://www.project.com.ph/$1" [L,NC,R=301]
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.
On our website using Joomla we have duplicate URLs for the same page being found by Google Webmaster Tools. For instance the following URLs go to the same page on our site:
/lawson-equipment/auxiliary-equipment/poly-pro-sinks?option=com_content&view=article&id=75&Itemid=74
/lawson-equipment/pre-press/poly-pro-sinks/index.php?option=com_content&view=article&id=75&Itemid=74
/technical-support/digital-learning?option=com_content&view=article&id=75&Itemid=74
/lawson-equipment/textile-equipment/dryers/encore-dryer
with the fourth URL being the actual path I want. How would I go about formulating a rewrite rule that would grab any URL query strings with "&id=75" to be directed to the SEF URL without doing a Redirect 301 for each of the incorect URLs? This happens often.
Success! Using a RewriteCond command with a common snippet from the non-SEF addresses, and a RewriteRule command for the target address using regular expressions I come up with the following for my .htaccess file:
RewriteCond %{QUERY_STRING} ^.*com_content&view=article&id=75&Itemid=74$
RewriteRule ^index\.php$ http\:\/\/www\.mysite\.com\/lawson\-equipment\/textile\-equipment\/dryers\/encore\-dryer? [R=301,L]
So far this seems to be working and hasn't affected anything else that I can see. Please feel free to comment or add another answer if there is a better way of doing this!