How to change one url suffix to another in apache? - 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

Related

Apache redirection to another port

I'm in trouble with understanding the apache configuration to redirect an http to another.
I need to redirect the following:
http://test.com/foo to http://test.com:34567
and
http://test.com/bar to http://test.com:33490
I have seen that with that lines it redirects to another address, but I need to know if it will work before doing anything.
Redirect permanent "/foo" "http://test.com:34567"
Redirect permanent "/bar" "http://test.com:33490"
Thank you!
Yes, it works, If anyone wants, I tried it in https://htaccess.madewithlove.be/

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

Apache rewrite url help, add string in the middle of the url

I need some help with my apache rewrites since I am quite bad at it.
I want to make an apache rewrite rule where I can rewrite links from my old site format to the new one.
http://foo.bar/old/$1 to http://foo.bar/new/$1. This should also work when old is a random string or empty.
Thanks in advance.
If anyone has the same issue as i did, i found the solution:
RedirectMatch 301 ^/([-0-9a-zA-Z])/(.)$ http://foo.bar/new/$2

remove specific filename .htaccess

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.

use RewriteMap in htaccess file

How can i use RewriteMap directive in htaccess file?
When i put it there i get "RewriteMap not allowed here" error.
I know this error will disappear when put it in httpd.conf or virtualhost configuration file.
But i want to know is it possible to put it in htaccess or not?
From the documentation:
Context: server config, virtual host
so the answer is "no", I'm afraid.
As far as I know it cannot be used in htaccess.
Maybe you could check this out as an alternative: http://savride.wordpress.com/2008/09/09/rewritemap-directive-in-htaccess-file-problem/