[英]How do I redirect non-existant subdirectory in my index.php file, keeping the URL
I want to basically be able to goto, for example: www.example.com/my/folder/ where the subdirectories /my/folder/ don't exist, and have it redirect to index.php?path=/my/folder, while still keeping the original URL. 我想基本上能够转到,例如:www.example.com/my/folder/其中子目录/ my / folder /不存在,并将其重定向到index.php?path = / my / folder ,同时仍保留原始网址。
I hope this makes sense. 我希望这是有道理的。 I basically have no idea where to start with this.
我基本上不知道从哪里开始。 I'm guessing it's something with .htaccess, or http.conf or something, but I have no clue.
我猜它是.htaccess或http.conf之类的东西,但我不知道。
I basically want some direction on where to figure out how to do this, or some suggestions. 我基本上想要在哪里找出如何做到这一点或一些建议。
I always liked borrowing from the Wordpress .htaccess
file myself 我一直喜欢借用Wordpress
.htaccess
文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This little bit of code will rewrite anything that is not a file and send it to your index.php file. 这一小段代码将重写任何不是文件的内容并将其发送到index.php文件。 You can then parse
$_SERVER['REQUEST_URI']
for anything you need from the URL itself. 然后,您可以从URL本身解析
$_SERVER['REQUEST_URI']
以获取所需的任何内容。
It depends on what web server you're running. 这取决于您正在运行的Web服务器。 If you're running Apache, then yes, it's in the
.htaccess
file or the VirtualHost
file. 如果您正在运行Apache,那么是,它位于
.htaccess
文件或VirtualHost
文件中。 In addition, mod_rewrite
will need to be enabled on your Apache server for this to work. 此外,需要在Apache服务器上启用
mod_rewrite
才能使其正常工作。
sudo a2enmod mod_rewrite
sudo service apache2 restart
Other web servers will have it in different locations and require different commands. 其他Web服务器将它放在不同的位置并需要不同的命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.