我正在尝试允许清洁Urls,启用MultiViews。
我所有的页面,都在根文件夹中。
我正努力做到以下几点:
(current-status -> what I am trying to achieve)
1. foo.com/services.php -> foo.com/services
2. foo.com/services == foo.com/services/
3. foo.com/services.php/second-level/ == foo.com/services/second-levelservices是而不是的一个文件夹,我爆炸$_SERVER['PATH_INFO']并获取二级路径数据.
我已经完成了第一个步骤,但是当我启用MultiViews、使用.htaccess文件并编写重写时,它就失败了。
Options +Indexes +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L](这显然会失败,因为它会将请求更改为services/二阶. the )。我知道我可以在.htaccess中编写多个重写,并有条件地重定向。
但奇怪的是,在活动环境(共享托管)上,它正在工作,在根文件夹中没有任何.htaccess文件。因为它是一个共享主机,所以我无法读取配置文件。
对于我应该更改什么配置(在apache.conf或*.conf中)以实现上述目标,有什么想法吗?
如果重要的话,我正在使用Apache/2.2.22,这个问题在更新之后就开始发生了。
发布于 2013-01-13 18:38:26
我终于想出了解决办法。
这可以完全删除.htaccess文件,并更改Virtual Directory以保持以下设置:
<VirtualHost *:80>
ServerAdmin my-email-id
ServerName foo.bar
DocumentRoot /var/www/sites/foo/
<Directory /var/www/sites/foo/>
Options +FollowSymLinks +MultiViews +Indexes
DirectoryIndex index.php
AddType application/x-httpd-php .php
</Directory>
</VirtualHost>这可以帮助我使所有页面正常工作,就像它们在服务器上工作一样,而不需要任何重写条件。
发布于 2014-12-29 23:51:22
在不使用.php扩展和不使用MultiViews的情况下清除URL。
一个灵活的Web环境,使用userdir和重写提供虚拟子域支持。
允许以下url布局
http://foo.bar/services.php/second-level/http://foo.bar/services/second-level/http://www.foo.bar/services/second-level/http://127.0.0.1/services/second-level/
http://foo.bar/admin/login.php/foohttp://foo.bar/admin/login/foohttp://www.foo.bar/admin/login/foo
注:有或不加前缀的www。是平等的因为。今天已经过时了。但是现在您也可以通过在/var/www/sites/中添加一个文件夹来托管虚拟子域(请记住DNS)。
http://images.foo.bar/imgpass.php/photo.jpghttp://images.foo.bar/imgpass/photo.jpghttp://www.images.foo.bar/imgpass/photo.jpghttp://127.0.0.1/~images/imgpass/photo.jpg
...and等,但跳过了if /var/www/site/映像/imgpass本身。
我使用的是一个多用户环境,每个用户都有自己的webroot和子域。
/etc/apache2/sites启用/foo.bar.conf:
<VirtualHost *:80>
ServerAdmin my-email-id
ServerName foo.bar
ServerAlias 127.0.0.1 *.foo.bar
# The default web-root if no subdomain is given
DocumentRoot /var/www/sites/www/
UserDir /var/www/sites/*
<Directory /var/www/sites/*>
Order allow,deny
Allow from all
DirectoryIndex index.php index.html
Options -MultiViews -Indexes
# MultiViews workaround with 1 level subdir support
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} ^(\/var\/www\/sites\/.+(\/[^\/]+){2}).*
RewriteCond %1.php -f
RewriteRule ^\/var\/www\/sites\/(.+)((?:\/[^\/]+){2})(.*) /~$1$2.php$3 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} ^(\/var\/www\/sites\/.+(\/[^\/]+){1}).*
RewriteCond %1.php -f
RewriteRule ^\/var\/www\/sites\/(.+)((?:\/[^\/]+){1})(.*) /~$1$2.php$3 [L]
</Directory>
# Force all requests in background to UserDir compatible requests
RewriteEngine on
RewriteMap lc int:tolower
RewriteCond %{REQUEST_FILENAME} !^/~
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)\.foo\.bar$
RewriteRule /(.*) /~${lc:%2}/$1 [PT,L]
</VirtualHost>此代码不是testet,因为我的文件系统结构与初始示例完全不同。因此,我动态地转换了我的配置,以适应这个示例结构。
注意配置是不完整的。你需要自己调整它以满足你的需要。
https://stackoverflow.com/questions/14182741
复制相似问题