문제

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.

도움이 되었습니까?

해결책

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]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top