0

I have about 30 landing page directories in my site's root directory, and for neatness I want to move all the files to a /landing directory. I want all the public vanity URLs for the landing pages still to work and NOT to show the 'landing' directory in the address bar.

For instance, I want www.site.com/happiness

to display content stored in my /landing/happiness directory, but I want the url in the address bar still to show www.site.com/happiness.

What I have in my .htaccess now is

RewriteRule ^happiness(.*)?$ landing/happiness$1 [NC,L,QSA]

This shows the content fine but rewrites the URL in the address bar and exposes the 'landing' directory. How do I do the rewrites in the .htaccess so that the files served are in the landing directory but the address bar shows the original vanity URL?

Thanks for any help!

4

1 に答える 1

-1

これは、末尾にスラッシュを付けずにディレクトリ URL を入力した場合に発生します (/happinessたとえば、 または/happiness/subdir. この場合、末尾にスラッシュが付いmod_dirたURL へのリダイレクトを発行します。

内部リダイレクトの末尾に常にスラッシュを追加することで、これを回避できます。

RewriteRule ^happiness(?:/.*)?$ landing/$0/ [NC,L,QSA]

これの欠点は、PHP ファイルであっても、常に最後にスラッシュがあることです。

于 2013-02-26T00:42:22.333 に答える