How to replace an url part through htaccess

ru flag

As I am not able to change my URLs through my application, I try to just rewrite the URLs via .htaccess.

I try to change my URLs from:


From what I have researched, this should do the trick, but it doesn't:

RewriteEngine On
RewriteRule ^/mietgeraete_cat/(.*)$ /baumaschinen/$1 [QSA]

What would be the right way to go?

kz flag
This question is better asked on [Webmasters]( since it's about userland development, not server config. However, unless you can actually "change the URL in your application", then this is unlikely to work (and depends to a certain extent on your application). Does your "application" not generate it's own links? How are URLs routed? The directive you posted (which is incorrect) doesn't "change" the URL, it allows another URL to "work" (but that is dependent on the application). URLs cannot be "changed" with `.htaccess` alone.
in flag

I assume that mietgeraete_cat is the actual folder on your server and baumaschinen is the URL you want to have.

If this is the case, you made a pretty common error, you misunderstood the direction of the rewrite. You don't rewrite the folder/filename to the URL, you rewrite the URL to the actual folder/filename.

It should be:

RewriteRule ^/baumaschinen/(.*)$ /mietgeraete_cat/$1 [L]

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.