0

I want to change an url-alias via htaccess. Here is one example, how one url should be changed:

original url:

www.domain.de/immobilien-vermarktungsart/miete

future url:

www.domain.de/immobilien-leipzig/mieten

Is it possible only to change the url-alias?

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
tom84
  • 371
  • 1
  • 3
  • 15
  • What exactly do you mean by "url-alias"? You certainly can rewrite such requests, internally or externally, if that is what you mean. But the `Alias` as the apache http server defines it is something that cannot be altered in a dynamic manner, so in `.htaccess` style files. That does not make sense. – arkascha Nov 04 '16 at 09:51
  • thanks for your answer! i want to change the url string from www.domain.de/immobilien-vermarktungsart/miete to www.domain.de/immobilien-leipzig/mieten – tom84 Nov 04 '16 at 10:05
  • That would be a typical external redirection. There are about 649265936498 answers to this alone here on SO. I suggest you take a look at a few of those. You will easily find your way around. You could for example start on the right hand of this page under "Related"... Also the documentation of the apache commands `Alias`, `Redirect` and `RewriteRule` should answer your question. – arkascha Nov 04 '16 at 10:06
  • thanks for your answer. i know the possibility to make a 301 redirect with htaccess. But this is not the right way because i only want to rewrite the string in the url... – tom84 Nov 04 '16 at 10:24
  • Again you are vague and unclear: what does that mean "i only want to rewrite the string in the url"? – arkascha Nov 04 '16 at 10:26
  • i try it :-) i want to change the name of the url... like my example: at the moment the url looks like this: www.domain.de/immobilien-vermarktungsart/miete and want to change the charakters of the ulr in www.domain.de/immobilien-leipzig/mieten – tom84 Nov 04 '16 at 10:35
  • Yes, you said so. But the question is: _where_ do you want to change it and why? If you change it in the browser, then that _is_ an external redirection. If that is to be done only in the server, then that is an internal redirection. Both is possible as already said in the beginning. So what is your actual question? Don't try to explain how you think you might be able to achieve whatever you want to do. Explain what you want to happen from the client side perspective. – arkascha Nov 04 '16 at 10:37
  • i look fo an internal redirection... but i things like `RewriteRule ^/immobilien-vermarktungsart/miete/(.*)$ /immobilien-leipzig/mieten [NC,L]` did not work – tom84 Nov 04 '16 at 10:42
  • "did not work" never helped anyone anywhere at any time. _Be specific_. How else do you expect us to help? What does that mean? Nothing happened? You got an error? You got a white page? The universe imploded? Add you attempt to the question and explain in details what happened, what is wrong with that. – arkascha Nov 04 '16 at 10:44
  • after i write this rule in my htaccess the site was still accessible (no errors). When i opened the site with this url: /immobilien-vermarktungsart/miete the url did not change into /immobilien-leipzig/mieten. and no the universe did not implode... – tom84 Nov 04 '16 at 10:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/127367/discussion-between-tom84-and-arkascha). – tom84 Nov 04 '16 at 10:51
  • Possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – RJHunter Nov 04 '16 at 11:25

1 Answers1

1

The discussion reveals that you are looking for a combination of an external and an internal rewriting:

RewriteEngine on
RewriteBase /
RewriteRule ^/?immobilien-vermarktungsart/miete(.*)$ /immobilien-leipzig/mieten$1 [R=301,QSA]
RewriteRule ^/?immobilien-leipzig/mieten(.*)$ /immobilien-vermarktungsart/miete$1 [END,QSA]

This will change the visible URL in the broser from immobilien-vermarktungsart to immobilien-leipzig, but internally still deliver the contents of immobilien-vermarktungsart.

arkascha
  • 41,620
  • 7
  • 58
  • 90