remove specific filename .htaccess - apache

I have site:
mysite.com/welcome
I wan't to remove the welcome-part of the url, but only IF the part is == welcome
for example:
mysite.com/welcome => mysite.com/
mysite.com/contact => mysite.com/contact
In any other case, the name after mysite.com stays the same.
I know it has something to do with the .htaccess-file on my server, but I can't figure out
how exactly I have to realize it. I assume I have to use regular expressions?
Thanks for any help

You can use this rule to remove welcome only:
RedirectMatch 301 ^/welcome$ /
Place this rule in your root .htaccess.

Related

Htaccess Redirect with Regular Expressions

I have a question regarding htaccess configuration win a PHP Project
I have this code to use redirection
DirectoryIndex src/client/index.php
Redirect /app/about http://localhost/app/?p=about
Redirect /app/contact http://localhost/app/?p=contact
Inside src/client/index.php I check the GET[p] to include the page requested.
It works... but I dont want to modify the htaccess file each time I add a new page.
I would like to implement something like this but it doesnt work, Im pretty sure I have syntax errors
Redirect ^/app/(.*) http://localhost/app/?p=$1
Thanks for your time :)
You just need to use RedirectMatch:
RedirectMatch ^/app/(.*) http://localhost/app/?p=$1

Remove /amp from URL with .htaccess

I need to use .htaccess to remove /amp from a certain URL structure. I have incoming links that look like this:
https://domain/store/amp and https://domain/store/product/amp
In both cases, the /amp on the end results in 404 errors. I just need to get rid of it, because fixing the problem at the source is not currently an option. I intend to put the .htaccess in the /store/ directory path.
I have looked around for similar examples and tried to modify them, but rewrites make my head spin in short order. Thanks for the help.
You can use this Redirect
RedirectMatch 301 ^/(.+)amp$ /$1

Trying to redirect anything after the full URL without /68 for example

I need to remove anything on the end of URLs like the below examples without the /68 or any number ID
https://www.website.com/forum/making-coffee/68 <-- I would like to remove the / and anything after so it looks like this below.
https://www.website.com/forum/making-coffee
I've searched but can't get the redirect to work correctly.
Any idea?
You can use this rule in your root .htaccess
RedirectMatch 301 ^/(.+?)/[0-9]+$ /$1

How to change one url suffix to another in apache?

I hope I can explain this clearly enough, but if not let me know and I'll try to clarify.
I need to configure apache to redirect from one url to another e.g. mySite.com/maven2 should redirect to mySite.com/content/maven2. Do you have any idea how I should do this?
In php you can do this with:
header("LOCATION: mySite.com/content/maven2");
Or you can use a meta refresh...
Take a look at the Redirect Apache directive.
Redirect /maven2 http://example.com/content/maven2
You can use that in either .htaccess or httpd.conf

redirect with htaccess

i need to redirect temporally a domain to a subdomain, this is my code for .htaccess:
Redirect 302 / http://m.domain.com/
this works great, but i have some subdirectories like: http://domain.com/photos, the code above redirects this way: http://m.domain.com/photos
i have a lot of subdirs and sub-subdirs, how i can redirect successfully all the subdirs to the same subdomain? (http://m.domain.com/)
Check out this post, I think it might help you. It looks like all you'd need to do is change your redirect to look something like:
Redirect 302 ^/.+/.*$ http://m.domain.com/
.htaccess redirect loop! All subdirectories to root
Hey, this is a tool for generating the redirect code, and lets you choose how the final URL looks, without knowing regex. Might help you.