htaccess static url rewrite - .htaccess

I am working on wordpress blog and the its has the url pattern something like this. localhost/blog/2012/10/12/sample-post/ .
Now i have updated the url pattern to localhost/blog/sample-post/.
Now i need a redirection to second URL pattern if someone enters the first URL Pattern as i have already submitted URLs with first pattern to couple of articles.
i.e, localhost/blog/2012/10/12/sample-post/ should be redirected to localhost/blog/sample-post/
Can anyone assist me by providing htacess code ?

Try adding these to the htaccess file in your document root. Make sure they are before any wordpress related rules:
RewriteEngine On
RewriteRule ^/?blog/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*)$ /blog/$1 [L,R=301]

Related

htaccess rewrite to new domain and url starting and ending with

My site's server is in the U.S. but I want to load images (and maybe later js and css) from a server in the visitors' country itself. I'm wondering what's a good way of rewriting only the images' urls that are in a specific directory.
Current url
http://www.myusserver.com/wp-content/uploads/image-name.jpg
url I want to use
http://www.myvisitorsserver.com/wp-content/uploads/image-name.jpg
I found this rewrite rule that does the job
RewriteRule ([^.]+\.(jpe?g|gif|bmp|png))$ http://www.myvisitorsserver.com/$1 [R=301,L,NC]
but I want to limit it to only images that are in the /wp-content/uploads directory.
I changed the rewrite to this
RewriteRule ^wp-content/uploads/ http://www.myvisitorsserver.com/wp-content/uploads/$1 [R=301,L,NC]
I think it's working, but I'm wondering if it's possible to rewrite only image urls. So, basically what I need is is to know how to rewrite and url starting with /wp-content/uploads and ending with an image extension.
I like this rule
RewriteRule ([^.]+\.(jpe?g|gif|bmp|png))$ http://www.myvisitorsserver.com/$1 [R=301,L,NC]
but I don't know how to change the first part of it to match /wp-content/uploads
Can anyone help me with this?
Thank you
I want to rewrite to the url structure as I mentioned in the 2nd example
Then just prefixing your rule pattern with the static path should work:
RewriteRule ^(wp-content/uploads/[^.]+\.(jpe?g|gif|bmp|png))$ http://www.myvisitorsserver.com/$1 [R=301,L,NC]

how to rediect form htaccess file?

I want to redirect from http://www.example.com/index.php?abz_xyz to http://www.example.com/abz_xyz with htaccess. I am using this code on my htaccess file Redirect /index.php?abz_xyz http://www.example.com/abz_xyz/ but this is not working kindly please help me
Something like this (my regex may be off)
The [L] means Last, so once the rewrite engine hits that line, it'll redirect immediately if it matches
RewriteEngine On
RewriteRule ^index\.php\?abz_xyz$ /abz_xyz/ [L]

Redirect rule in .htaccess to catch all URL's that are not in the .htaccess file

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

.htaccess rewrite from domain/ to domain/nl/

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.

Redirect URLs using partial query string

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!

Resources