.htaccess 使用htaccess从url中删除文件夹

niwlg2el  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(254)

因此,我有一个名为页面的文件夹,其中包括我的网站的页面,当打开这些文件之一的网址读-

斑马鱼网页/页面/联系方式

我希望它只是读

斑马鱼网/联系人

我已经有了这个htaccess文件来删除任何.php .html扩展名,我也想继续使用。我没有一个线索如何写这些htaccess文件只是从网上复制它,并为我量身定制!

RewriteEngine on

 RewriteRule ^(themes|order-now|submissions|faq|contact)$ $1.php [NC,L]
 RewriteRule ^(home|faq)$ $1.html [NC,L]
irtuqstp

irtuqstp1#

1.您已经在/pages/子目录中有一个.htaccess,其中包含.php.html扩展的一些规则
1.您希望重定向到较短的URI /contact而不是/pages/contact
有了这些,你就可以有这样的规则:
站点根.htaccess

RewriteEngine On

RewriteRule ^contact/?$ pages/contact.php [L,NC]

pages/.htaccess

RewriteEngine On

# redirect to shorter URL
RewriteCond %{THE_REQUEST} /pages(/contact)[?\s]
RewriteRule ^ %1 [L,R=302]

# add .php to these files
RewriteRule ^(themes|order-now|submissions|faq|contact)/?$ $1.php [NC,L]

# add .html to these files
RewriteRule ^(home|faq)/?$ $1.html [NC,L]

相关问题