【发布时间】:2016-07-01 16:19:13
【问题描述】:
我的 htaccess 文件完美地从所有 php 文件中删除了所有文件扩展名,这很好,但是我需要将文件/页面 booking.php 从其中排除并加载 .php 扩展名。实现这一目标的最佳方法是什么?我在 Ubuntu 14.04 上使用 Apache 2.4.7
我当前的 htaccess 文件:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{THE_REQUEST} \s/+sections/(.+?)(?:\.php)?[/?\s] [NC]
RewriteRule ^ %1 [R=301,L]
# remove index
RewriteCond %{THE_REQUEST} /index(\.php)?[\s?/] [NC]
RewriteRule ^(.*?)index(/|$) /$1 [L,R=301,NC,NE]
# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [L,R=301]
# remove index
RewriteRule (.*)/index$ $1/ [R=302]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301,L]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^sections/)^(.+)$ /sections/$1 [L,NC]
</IfModule>
我尝试了一些方法,但没有任何结果,因为总是导致 404 并且从不保留文件扩展名。一些专家的帮助将不胜感激
【问题讨论】:
标签: regex apache .htaccess ubuntu