htaccess rewrite url for laravel project to exclude folder directory from url

Viewed 251

I have instaledl ubuntu 16.04 server and I have lots of laravel projects in /var/www/html with numeric folder like below:

<pre>
    121744
       content
         app
         bootstrap
         config
         database
         public
         resources
         routes
         storage
         tests
         vendor
         composer.json
         composer.lock
         server.php   
         ....
</pre>


<pre>
    12877
       content
         app
         bootstrap
         config
         database
         public
         resources
         routes
         storage
         tests
         vendor
         composer.json
         composer.lock
         server.php   
         ....
</pre>

<pre>
    8798
       content
         app
         bootstrap
         config
         database
         public
         resources
         routes
         storage
         tests
         vendor
         composer.json
         composer.lock
         server.php   
         ....
</pre>

As per above folder to open laravel application in the browser the url look like below:

http://example.com/121744/content/public

http://example.com/12877/content/public

http://example.com/8798/content/public

The content in the url is common. I want to remove content from url so that the url should look like below:

http://example.com/121744/public

http://example.com/12877/public

http://example.com/8798/public

The location of .htaccess file in var/www/html/.htaccess.

Please help me, how do I make htaccess do this?

1 Answers

Could you please try following.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(\d+)/content/([\w-]+)/?$ /$1/$2 [NC,L]

In case your public directory is fixed each time then try:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(\d+)/content/(public)/?$ /$1/$2 [NC,L]
Related