【发布时间】:2019-06-19 10:41:32
【问题描述】:
我的网站结构如下:
- index.php
- css/
- js/
- img/
- content/
- product/
- product-page-1.php
- product-page-2.php
- static/
- faqs.php
- landing/
- homeware-gifts.php
- stationary/
- desks.php
所以目前我的一些网址是这样的,但我需要隐藏 content 和 product, static, landing 目录
产品:
mysite.com/content/product/product-page-2.php
到
mysite.com/product-page-2
静态:
mysite.com/content/static/faqs.php
到
mysite.com/faqs
着陆:
mysite.com/content/landing/homeware-gifts.php
mysite.com/content/landing/stationary/desks.php
到
mysite.com/homeware-gifts
mysite.com/stationary/desks
注意我也想隐藏 .php 扩展名,我目前正在使用这个:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
这可行,但需要确保它也保持不变
【问题讨论】:
-
所以如果 URL 是
mysite.com/aboutus那么aboutus.php可以在product/、static/、landing/中或找不到。这可以做到,但效率会有点低,因为它需要检查 3 个目录中是否存在php文件。 -
如果更简单,我可以将所有 php 页面文件移动到
content目录中吗?所以忽略产品/静态/登陆目录 -
是的,那太好了,我会根据这个假设发布答案。
标签: .htaccess redirect directory