URL重写与指数在"公开];夹 [英] URL-rewriting with index in a "public" folder

查看:123
本文介绍了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文件是一个名为公共文件夹

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

要更清楚,这是我现在已经到达了建网站的主页的网址: 的http://域名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

我关心的是有关文件夹公众:它出现在URL中,我不想。 这是我想获得的网址: 的http://域名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证拿到放在这个文件夹公共的索引文件。

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路径,你需要从你所有的链接删除它,二,关闭多视图,这不是你想要的,第三,你需要一个规则,外部重定向浏览器时,发出请求的 /公/ ,那么你就需要在内部重写请求指向公众。

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天全站免登陆