如何通过mod_rewrite从URL中删除两个子目录?(How to remove two subdirectories from a URL via mod_rewrite?)
我试图重写一个URL来删除两个子目录,并在根目录中显示该页面。 这是我在.htaccess中使用的代码:
RewriteRule ^page$ subdirectoryone/subdirectorytwo/page [NC,QSA,L]
这是我在根目录中的完整.htaccess文件:
Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTPS_HOST} ^mysite.com RewriteRule (.*) https://www.mysite.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^mysite.com RewriteRule (.*) https://www.mysite.com/$1 [R=301,L] RewriteCond %{SERVER_PORT} !=443 RewriteRule ^(.*)$ https://www.mysite.com/$1 [R=301,L] # remove trailing slashes RewriteRule (.*)/$ $1 [L,R=301] RewriteRule ^page$ subdirectoryone/subdirectorytwo/page [NC,QSA,L]
这是第一个子目录中的.htaccess:
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /subdirectoryone/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /subdirectoryone/index.php [L] </IfModule> # END WordPress
但是,当我打开URL www.mysite.com/page时,它会显示错误404.顺便说一句:我使用的是Wordpress,安装在第一个子目录中 - 这有什么不同吗?
此外,它只在我删除两个子目录中的第一个时才有效。
有任何想法吗? 提前致谢!
I am trying to rewrite a URL to remove two subdirectories and display the page in the root directory instead. This the code I use in my .htaccess:
RewriteRule ^page$ subdirectoryone/subdirectorytwo/page [NC,QSA,L]
This is my complete .htaccess file in the root directory:
Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTPS_HOST} ^mysite.com RewriteRule (.*) https://www.mysite.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^mysite.com RewriteRule (.*) https://www.mysite.com/$1 [R=301,L] RewriteCond %{SERVER_PORT} !=443 RewriteRule ^(.*)$ https://www.mysite.com/$1 [R=301,L] # remove trailing slashes RewriteRule (.*)/$ $1 [L,R=301] RewriteRule ^page$ subdirectoryone/subdirectorytwo/page [NC,QSA,L]
This is the .htaccess in the first subddirectory:
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /subdirectoryone/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /subdirectoryone/index.php [L] </IfModule> # END WordPress
However, when I open the URL www.mysite.com/page it displays an error 404. By the way: I am using Wordpress, installed in the first subdirectory – does that make any difference?
Also, it works when I only remove the first of the two subdirectories.
Any ideas? Thanks in advance!
原文:https://stackoverflow.com/questions/17577558
最满意答案
这是B / C你必须指定你的环境。
默认情况下是“prod”和“dev”。
所以如果你想让控制台为你的开发环境做些什么
./console --env=dev [...]
该错误消息源于控制台试图加载适当的配置文件,其中config_dev.yml为“dev”,config_prod.yml为“prod”,config_.yml为“”; 但那个不存在。
That is b/c you have to specify your environment.
Available by default are "prod" and "dev".
So if you want to have console do something regarding your development environment you do
./console --env=dev [...]
The error message stems from console trying to load the appropriate configuration file, which is config_dev.yml for "dev" and config_prod.yml for "prod" and config_.yml for ""; but that one doesn't exist.
相关问答
更多-
如果你从ContainerAwareCommand扩展你应该能够得到你的服务 $this->getContainer()->get('doctrine'); 这是类似的问题 If you extend from ContainerAwareCommand you should be able to get your service $this->getContainer()->get('doctrine'); Here is similar question
-
Symfony2控制台HelperSet(Symfony2 console HelperSet)[2022-05-11]
看起来应用程序和命令可以有不同的帮助程序集,所以我解决了问题 namespace My\Console\Command; use Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand as BaseCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class C ... -
为了跟进,回答我的问题---我必须创建一个自定义安装步骤来更新PATH环境变量,使计算机从任何CMD窗口看到我的新控制台应用程序。 这意味着执行两个步骤:读取当前路径(不扩展每个字符串中的变量),如下所示: string RegKeyName = @"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; string pathvariable = (string)Microsoft.Win32.Regis ...
-
Symfony2应用程序/控制台--env不会引发envirorment名称(Symfony2 app/console --env throws no envirorment name)[2023-04-21]
这是B / C你必须指定你的环境。 默认情况下是“prod”和“dev”。 所以如果你想让控制台为你的开发环境做些什么 ./console --env=dev [...] 该错误消息源于控制台试图加载适当的配置文件,其中config_dev.yml为“dev”,config_prod.yml为“prod”,config_.yml为“”; 但那个不存在。 That is b/c you have to specify your environment. Available by default are "p ... -
一个好的起点始终是控制台组件的文档 。 IgorW的composer-yaml可以作为单个文件控制台应用程序的示例。 您还可以通过查看作曲家的bin / composer , src / bootstrap.php , src / Console / Application.php以及src / Command / AboutCommand.php来获得灵感 。 只需将作曲家的bin/composer和src/bootstrap.php合并到你的bin/init.php ...... ...然后将PSR-0 ...
-
显然这是一个已知的错误 https://github.com/symfony/symfony/issues/14426 https://github.com/symfony/symfony/issues/7555 解决方法,但还没有修复 apparently it's a known bug https://github.com/symfony/symfony/issues/14426 https://github.com/symfony/symfony/issues/7555 workarounds, b ...
-
ENV它不是Rails特有的,它是访问系统环境变量的Ruby对象。 查看此处的文档 ENV it's not Rails specific, it's Ruby object to access the system environment variables. Look the documentation here
-
Eclipse for BlackBerry,设置Eclipse环境(Eclipse for BlackBerry, set up the Eclipse envirorment)[2023-11-28]
这个过程仍然不是很顺利。 看看这篇文章,可能会有所帮助: http://www.blackberryforums.com/developer-forum/138210-setup-up-eclipse-blackberry-development.html this is still not very smooth process. Check out this post, may be it will help: http://www.blackberryforums.com/developer-foru ... -
在生产环境中,当你运行app / console cache:warmup命令时,你需要确保你这样运行它: app/console cache:warmup --env=prod --no-debug另外,请记住命令会热身缓存作为当前用户,因此所有文件将由当前用户拥有,而不是Web服务器用户(例如:www-data)。 这可能是您收到500服务器错误的原因。 预热后,缓存运行: chown -R www-data.www-data app/cache/prod (务必用您的Web服务器用户替换www-dat ...
-
检查PHP配置中的open_basedir设置。 关闭它可以解决您的问题。 将PHP可以访问的文件限制到指定的目录树,包括文件本身。 此指令不受安全模式是打开还是关闭的影响。 当脚本尝试访问文件系统时,例如使用include或fopen(),将检查文件的位置。 当文件在指定的目录树之外时,PHP将拒绝访问它。 所有符号链接都已解析,因此使用符号链接无法避免此限制。 如果文件不存在,则无法解析符号链接,并将文件名与(已解析的)open_basedir进行比较。 Check your open_basedir ...