我有一些麻烦,以获得.htaccess文件的正确configuration。
我使用mvc模式制作了一个小站点,所有的url都像site.com/appname/public/index.php?param=page。 我试图让所有url写为site.com/page。 我search了Apache文档,但我仍然困惑…
这是我现在在/ public目录中的:
Options -MultiViews RewriteEngine on RewriteBase /appname/public/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
这是我在根目录中的:
RewriteEngine On RewriteRule ^(.*)$ appname/public [R=301,L]
这工作正常,它redirect到index.php(在/公共目录),并重写所有url到site.com/appname/public/page。
现在我triyng得到更多,我也会隐藏/ appname /公共,但我不能undestand如何。 我应该结合更多的RewriteRule来匹配“/ appname / public”吗?
有什么build议么?
非常感谢!
编辑:关于我想要实现的更多信息。
我有一个目录树,如:
htdocs |---appname | |---app | |---other_dirs | |---other_files | |---public |---some_dirs/file |--- index.php
为了访问我的网页,我需要指向浏览器index.php并传递一些GET值。 所以,所有的url应该是这样的:
site.com/appname/public/index.php?val=page
这是我现在(上面的规则)
site.come/appname/public/page
这就是我想要得到的…
site.com/page
我不知道如何重写/隐藏中间部分,保持最后一个结构“?url = $ 1”(“url”将在控制器中处理,parsing等等)。
我希望更清楚。
谢谢! 🙂
我不明白这个问题。 请澄清。
在documentroot目录中的RewriteBase目录? 你想消除什么?
Apache Manual Mod_Rewrite
提供了很多关于如何pipe理mod_rewrite的例子和细节
先看看那里,请回答更多关于你的设置看起来像什么。
这是从该页面拉,并详细说明为什么你使用rewritebase。 你希望在htdocs文件夹中删除所有文件夹,还是在公共docroot或htdocs或www之外,或者你已经命名了文档根目录的文件夹?
RewriteBase指令 说明:设置每个目录重写的基本URL 语法:RewriteBase URL-path 默认:无 上下文:目录,.htaccess 覆盖:FileInfo 状态:分机 模块:mod_rewrite RewriteBase指令指定用于replace相对path的每个目录(htaccess)RewriteRule指令的URL前缀。 除非满足以下任一条件,否则在每个目录(htaccess)上下文中的replace中使用相对path时,此指令是必需的: 原始请求和replace位于DocumentRoot之下(而不是通过别名等其他方法可访问)。 包含RewriteRule的目录的文件系统path(后缀为相对replace)在服务器上也是有效的URLpath(这很less见)。 在下面的例子中,RewriteBase是必要的,以避免重写到http://example.com/opt/myapp-1.2.3/welcome.html,因为资源不是相对于文档根。 这种错误configuration通常会导致服务器在文档根目录下查找“opt”目录。 DocumentRoot /var/www/example.com 别名/ myapp /opt/myapp-1.2.3 RewriteEngine On RewriteBase / myapp / RewriteRule ^ index \ .html $ welcome.html