Redirect 301 www.example.com/directory/tour1 to www.example.com/tour1 - .htaccess

Hi I have a situation with the mytic HTACCESS file. Im trying to fix a broken URL.
this folder never existed was a permalink created in WP.I need to redirect 301 all this broken links to avoid problems with Google.
The URL used to be like this
www.example.com/directory/tour1, www.example.com/directory/tour2, www.example.com/directory/tour3 and so on.
Now the url has changed so all the tours are under the root
www.example.com/tour1, www.example.com/tour2...
I need to make that all the queries to www.example.com/directory/WHATEVER
to point to www.example.com/WHATEVER
Thanks for helping me understand this universe of redirections... \
i HAVE TRIED alot of codes, none of them does the job.
RewriteRule ^tulum-tours/(.*) http://www.aguaclaraproject.com/

In your .htaccess in your www-root use the following rule:
RewriteEngine on
RewriteRule ^tulum-tours/(.*)$ /$1 [R,L]
Change the R flag to R=301 after testing it works correctly. Read the documentation for more information.

Related

htaccess from old forum url to new one

until now I have always used htaccess to rewrite URLS in order to have non-SEF url to SEF urls.
Today I am facing a new challenge that honestly, beeing non confident in regular expression, I really don't know how to achieve.
I have a situation where a forum on a website of mine has been update in the following form:
previous link: www.domain.com/forum3/topic/name-of-topic/post/7548
new link: forum.domain.com/Topic-name-of-topic/
How do I intercept /post/37764 string and tell htaccess to not consider it?
And how to instruct the server to build that kind of url instead of the provious. I am very confused about it.
Any suggestion? Thank you very much. Is there any resource that I can read to help me better understand the case?
Thanks again.
EDIT
Florian answer is correct. I just added few mods to fit it better.
RewriteEngine On
#RewriteBase /
RewriteRule ^forum3/topic/([^/]+)/post/[0-9]+$ http://forum.domanin.com/Topic-$1/ [L,R=301]
RewriteRule ^forum3/topic/([^/]+)-[0-9]+$ http://forum.domanin.com/Topic-$1/ [L,R=301]
You can try this code :
RewriteEngine On
RewriteBase /
RewriteRule ^forum3/topic/([^/]+)/post/[0-9]+$ /Topic-$1/ [L,R=301]
/([^/]+)/ means that we want to catch a string containing one or more characters except / preceded and followed by a /.
This link might help you to test your .htaccess files :
Test your apache htaccess files online

Redirecting /folder/ to /file.html in magento

We published an article in the magazine with following url:
http://magnetic-sleep-machine.com/moves
Now we need to make sure when people put that URL they land to
https://magnetic-sleep-machine.com/moves.html
Please help me figure this out! .htaccess or use a magento (1.7) option?
There's a way to redirect using magento, but not sure if that's exactly what you want.
You could also try turning on multiviews, and let mod_negotiation take cure of fuzzy URL-file mapping, in your htaccess file:
Options +Multiviews
Or using mod_rewrite:
RewriteEngine On
RewriteRule ^moves/?$ /moves.html [L,R=301]
Or using mod_alias:
RedirectMatch 301 ^/moves/?$ /moves.html
Okay I found the way to do it using magento itself.
created a new Page
page link named as "moves"
added javascript for redirect to body of the page
next went to system>config>web>
set Auto-redirect to Base URL to NO
Voila, it works now.

Remove word from end of URL using htaccess

I have a bunch of URLs coming up as .../undefined which get a 404 error, and I'd like to know how to removed the word "undefined" from the end of the URL using .htaccess
I have looked at many posts about removing extensions, queries, and URL-internal folders, and have tried adapting those rules to suit my purposes, but so far I haven't been able to make it work. Any ideas?
Sample URL: http://www.theveggietable.com/blog/vegetarian-recipes/sandwiches/true-veggie-burgers/undefined
I just want the word "undefined" to be stripped out so that the user is automatically redirected to http://www.theveggietable.com/blog/vegetarian-recipes/sandwiches/true-veggie-burgers/
Thanks!
Try:
RewriteEngine On
RewriteRule ^(.*)/undefined/?$ /$1/ [L,R=301]
or:
RedirectMatch 301 ^/(.*)/undefined/?$ /$1/
redirect 301 should do the trick
redirect 301 /undefined http://www.theveggietable.com/blog/vegetarian-recipes/sandwiches/true-veggie-burgers/
You can use the mod_rewrite module in your .htaccess file to modify the URL. Although, it seems like you're doing something wrong in the back-end if you're getting those kinds of URL's. I would suggest looking into why you get undefined in the first place.
For more information on mod_rewrite, see this blogpost.

trying to redirect a link in joomla or .htaccess

we moved our joomla site and rebuilt. in the process a link got moved that we need to be as it was before.
before:
www.mysite.org/kindergym
now it lives here:
www.mysite.org/education/kindergym
it would seem that it would be easy to go into com_redirect and do this. however, it only works for the following
mysite.org/kindergym without the www
with the www attached writing the old url returns a 404 error page, not a redirect.
i tried to make a separate redirect with the www too and it wouldnt let me. i tried a separate module with no success and have played around with the .htaccess file (although i am not very knowledgeable about htaccess).
could someone explain the reason why this would be an issue? the difference between the two. i tried calling my host and they were less than helpful and actually told me what i wanted to do couldnt be done LOL.
thanks.
I take it the solution you have would work if you redirect the entire mysite.org to www.mysite.org?
If so, create a .htaccess file in the website root. Put the following inside it:
########## Begin - Redirecting non-www request to www
#
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.org [NC]
RewriteRule (.*) http://www.mysite.org/$1 [L,R=301]
#
########## End - Redirecting non-www request to www
You also need to make sure mod_rewrite is enabled on the apache-server, but I think most providers support that.
I suggest you post your full .htaccess here. However I think all you need is this rule:
RewriteRule ^(?!education/).*)$ education/$1 [L,NC]
The other two answers are good! but better implement 301 redirect in httpd.conf since it's compiled once on server restart. The same code in .htccess is interpreted for each and every HTTP request!

.htaccess Rewrite Based on Existence of Path in URL

Here's the scenario, I have a website that used to be a static HTML site and WordPress blog using a subdomain (http://blog.domain.com).
I recently combined everything into a single WordPress installation. To maintain old links I had to rewrite requests like "http://blog.domain.com/index.php/2010/10/16/post-name" to "http://domain.com/index.php/2010/10/16/post-name". My problem is that when trying to visit just "http://blog.domain.com", I get redirected to "http://domain.com" when I want it to go to "http://domain.com/index.php/blog".
So, if a user requests "http://blog.domain.com" (by itself, with or without slash), I want it to go to "http://domain.com/index.php/blog". If they request an old URL of "http://blog.domain.com/some-link-to-a-post", I want it to redirect to "http://domain.com/some-link-to-a-post". In other words, if it's a URL to an actual post, I just want to strip the "blog" subdomain. If it's the old link to the main blog page, I want to remove the "blog" subdomain and append "/index.php/blog"
http://blog.domain.com/ -> http://domain.com/index.php/blog
http://blog.domain.com/index.php/2010/10/16/post-title -> http://domain.com/index.php/2010/10/16/post-title
Hopefully that's clear. I'm not an htaccess expert, so hopefully someone can help me out here. Thanks in advance!
Using the [L] command at the end of a rewrite will tell htaccess that this is the last rule it should match. If you put a rule to match your first condition at the top and the other rewrite rule you said you had already created after it, you should get your expected result.
Try this:
RewriteRule ^blog.domain.com(/?)$ domain.com/index.php/blog [L]
# Your other rewrite here #
I couldn't get that solution to work. However, I used the following:
RewriteCond %{HTTP_HOST} ^blog\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/index.php/blog/$1 [R=301,L]
That ends up in a URL like http://domain.com/index.php/blog/index.php/2010/06/04/post-title, but Wordpress is smart enough to fix it.

Resources