Question

I would like to users to visit:

domain.com/example

and have the content from the following page displayed:

domain.com/directory1/directory2/directory3/example.html

In the browser, I would like it to say domain.com/example without redirecting. We have a series of landing pages that need to have short URLs within the domain.

I considered doing something programmatically such as a PHP include however I felt an .htaccess rewrite rule would be best practice.

Was it helpful?

Solution

So you want:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^example$ /directory1/directory2/directory3/example.html [L]

If you want it to work for every file (replacing "example" with any file) then replace the RewriteRule line with:

RewriteRule ^([^/]+)$ /directory1/directory2/directory3/$1.html [L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top