在“公共"中使用索引进行 URL 重写文件夹 [英] URL-rewriting with index in a "public" folder

查看:12
本文介绍了在“公共"中使用索引进行 URL 重写文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是开发领域的新手.我拼命尝试获得好的 URL.我检查了该站点是否存在类似问题,但我无法准确找到我需要的内容.或者我做得不好.

I’m a newcomer in the development world. I desperately try to get the good URL. I checked the site for similar problems but I can’t find exactly what I need. Or I do it badly.

情况是这样的:我为一个站点设置了一个项目,该站点的 index.php 文件位于名为 Public 的文件夹中.

Here is the situation: I set up a project for a site whose the index.php file is in a folder named Public.

更清楚地说,这是我现在可以访问已建站点主页的 URL:http://Domain Name.com/文件夹/站点名称/公共

To be clearer, here is the URL I have now to reach the homepage of the built site: http:// Domain Name.com/ Folder / Name of the site/public

我担心的是 Public 文件夹:我不希望它出现在 URL 中.这是我想要获取的 URL:http://Domain Name.com/文件夹/站点名称

My concern is about the folder Public: I don’t want it appears in the URL. Here is the URL I’d like to get: http:// Domain Name.com/ Folder / Name of the site

事实上,我希望这个 URL 允许获取放置在Public"文件夹中的索引文件.

In fact, I’d like this URL permits to get the index file placed in the folder "Public".

我无法访问 Apache 配置(共享主机),所以我在项目中放置了一个 .htaccess(即:www/文件夹/站点名称/.htaccess).这是它的内容:

I can’t access the Apache configurations (shared host) so I have a .htaccess I placed in the project (i.e: www/ Folder /Name of the site /.htaccess). Here is its content:

Options -Indexes +FollowSymLinks +Multiviews
RewriteEngine On
RewriteBase /public/
RewriteRule ^(.*)$ index.html [NC,L]

我现在做了一些非常简单的事情,因为我尝试了很多没有有效结果的事情.

I made something very simple for now because I tried lots of things without efficient result.

推荐答案

不太确定您要做什么,但是如果您想删除出现在 URL 中的 /public/ 路径,你需要把它从你的所有链接中删除,第二,关闭多视图,这不是你想要的,第三,你需要一个规则来在请求 /public/ 时从外部重定向浏览器,那么你需要在内部重写请求以指向公共.

Not really sure what you are trying to do, but if you want to remove the /public/ path that appears in the URL, you need to remove it from all your links, second, turn off multiviews, it's not what you want, third, you need a rule to externally redirect the browser when a request is made for /public/, then you need to internally rewrite requests to point to public.

Options -Indexes +FollowSymLinks -Multiviews
RewriteEngine On

# externally redirect, must match against %{THE_REQUEST}
RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST) /public/
RewriteRule ^/?public/(.*)$ /$1 [L,R=301]

# internally rewrite it back, but we must first check that it's pointing to a valid resource:
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -s
RewriteRule ^(.*)$ /public/$1 [L]

这篇关于在“公共"中使用索引进行 URL 重写文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆