Remove word from end of URL using htaccess - .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.

Related

Redirecting A File Anywhere In The Hierarchy

So, apparently some mobile ads drop a request for mraid.js into their page loads. That feels ridiculous to me, but there's not much I can do about that exactly. It looks like this:
If the page is /something, the request comes in as /something/mraid.js
But that also continues for cases like /something/else/mraid.js
No matter what the URL, it tacks on mraid.js.
I added a couple lines like this to the .htaccess file:
RedirectMatch 301 (.*)\mraid.js$ /mraid.js
or
RedirectMatch 301 ^\mraid.js$ /mraid.js
or
RewriteCond %{DOCUMENT_ROOT}/(.*)/mraid.js -f
RewriteRule ^(.*)$ /mraid.js [R=301,L]
With the hopes of redirecting them to a global (and blank) mraid.js file. This is just to load a file to stop the 404 errors in analytics, from what I'm told when mraid.js is needed it's loaded locally from within the mobile ad/app.
But none of those .htaccess rules seem to catch and redirect as I expect. Any ideas on how to always match mraid.js in the URL and pass it back to root?
After a bit more head-scratching, I figured it out. It was a combination of all three things that solved it for me. First, it had to match the pattern with ^(.*), then [L,R=301]. L for "this is the last rule", and R for "it's a permanent 301 redirect."
RewriteRule ^(.*)/mraid\.js$ /mraid\.js [L,R=301]

Set an index page for a specific folder in .htaccess

What I want to do should be quite simple: when the admin writes www.example.com/admin I want that he's addressed to www.example.com/admin/admin_index.php.
I wrote this rule and I checked on other posts here on Stackoverflow: it apparently seems to be correct, but it actually doesn't work.
RewriteEngine On
RewriteRule ^/admin/?$ /admin/admin_index.php [L,NC]
Has anyone any clue on why the redirect doesn't work, since it "stays" at www.example.com/admin outputting (obviously) the 403 error?
There is no need to use a rewrite rule. Just use DirectoryIndex directive in admin/.htaccess:
DirectoryIndex admin_index.php
This will load admin/admin_index.php when a request comes for http://domain.com/admin/

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

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.

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.

Redirect any url containing /foo/

I'm trying to redirect a series of around 400 urls using .htaccess/Apache containing a given /directory/ anywhere in the url to a specific location.
The problem here is that my site is receiving requests for an old site hosted on our servers ip. I've tried manually redirecting the urls but the volume is simply too great.
I've searched but can only find examples for redirecting query strings or files
Thanks in advance.
Ok, if all links have the same directory in there... example store/funstuff/blahblah.php
and funstuff is the directory you are looking for then you could modify your .htaccess file something linke this
Options +FollowSymlinks
Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_URI} funstuff
RewriteRule . http://www.gohere.com/
Then if you needed to pass more of the URL info you could do the last line like this:
RewriteRule ^(.*)$ http://www.gohere.com/1$
That should get you started... you may need to tweak it slightly.
What language are you processing the redirects in?
You probably need to use a regular expression that searches for the given /directory/.
If I understand your question correctly and that you are using Apache; RedirectMatch should do what you want.
It accepts a regexp for matching and can then redirect to the place you choose.

Resources