[英]Redirect everything to index.php without changing url
I am getting crazy trying to get this work.试图获得这项工作我快疯了。 I am planning a rather complex redesign of my whole website.
我正在计划对我的整个网站进行相当复杂的重新设计。 Since my website should work differently depending on which subfolder (eg www.mydomain.com/test123) you try to access, I think the easiest solution would be to redirect every single request to a main index.php and handle all cases from there.
由于我的网站应该根据您尝试访问的子文件夹(例如 www.mydomain.com/test123)以不同的方式工作,我认为最简单的解决方案是将每个请求重定向到主 index.php 并从那里处理所有情况。 I will also want to redirect images and css files etc. as I will handle those cases "manually" too.
我还想重定向图像和 css 文件等,因为我也会“手动”处理这些情况。
Here exactly what it should do:这正是它应该做的:
I have tried this but this wont work somehow...我试过这个,但这不会以某种方式工作......
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule ^(.*)$ /index.php?q=$1 [P]
Any help is greatly appreciated!任何帮助是极大的赞赏!
This rule should work for you in site root .htaccess:此规则应该适用于站点根目录 .htaccess:
DirectorySlash Off
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^(.+)$ /index.php?q=$1 [L,QSA]
No need to use P
flag that is used for proxying and that requires mod_proxy
to be enabled in Apache config.无需使用用于代理的
P
标志,并且需要在 Apache 配置中启用mod_proxy
。
You can use the include() function in php.您可以在 php 中使用 include() 函数。
ex前任
<?php
include('www.google.com');
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.