Xhantar
Xhantar

Reputation: 7448

How can I add an additional word to a URL using mod_rewrite

I have an application with URLs such as these:

https://www.domain.com/example/public/subscription
https://www.domain.com/example/public/subscription/source
https://www.domain.com/example/public/test/subscription

I'd like to use mod_rewrite (or some other method) to create shorter "aliases" of the above URLs by removing the /public/ part so that I can provide my client with these shorter versions of the URLs:

https://www.domain.com/example/subscription
https://www.domain.com/example/subscription/source
https://www.domain.com/example/test/subscription

In other words, when browsing to https://www.domain.com/example/subscription, for example:

Is this even possible, and how would such a RewriteRule look like?

Thank you in advance.

Upvotes: 0

Views: 569

Answers (2)

Olivier Pons
Olivier Pons

Reputation: 15778

You just want to "remove" the public keyword?

Try this rewrite rule:

RewriteRule ^/example/public/(.*) /example/$1 [L]

Upvotes: -1

ThinkingMonkey
ThinkingMonkey

Reputation: 12727

put this is .htaccess file in your DocumentRoot.

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine on
RewriteBase /

RewriteRule ^(example)/(.*)$ $1/public/$2 [NC,L]

Upvotes: 2

Related Questions