首页 \ 问答 \ 拒绝除/index.php和两个文件夹之外的所有文件夹(Deny from all folders except /index.php and two folders)

拒绝除/index.php和两个文件夹之外的所有文件夹(Deny from all folders except /index.php and two folders)

这是一个奇怪的配置,我会给你,但我想拒绝访问我们系统中的所有文件夹,但它必须能够访问,

/index.php (Wordpress bootloader)
/wp-*/* (e.g. wp-content, wp-admin, etc.)
/templates/* (some of our templates and custom content)

其他一切都被拒绝(并且有数百个文件夹)。

我遇到的问题是允许index.php和2个文件夹,然后拒绝/中的所有其他内容。

我应该能够接受,

http://example.com/
http://example.com/index.php
http://example.com/wp-content/...
http://example.com/wp-admin/...
http://example.com/wp-includes/...
http://example.com/templates/template.css
http://example.com/templates/subfolder/js/file.js

拒绝,

http://example.com/thisIsAFolder
http://example.com/thisIsAnotherFolder

这就是我所拥有的,

<VirtualHost *:80>
    ServerName example.com

    DirectoryIndex index.php
    DocumentRoot /var/www/

    <Directory />
        Order deny,allow
        Deny from all
    </Directory>

    <Files index.php>
        Allow from all
    </Files>

    <Directory "/var/www(/|/wp*/|/templates/)">
        Allow from all

        Options FollowSymLinks

        RewriteEngine On
        RewriteBase /

        RewriteRule ^index\.php$ - [L]
        RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d

        RewriteRule ^ - [L]
        RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) wp/$2 [L]
        RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ wp/$2 [L]
        RewriteRule . index.php [L]
    </Directory>
</VirtualHost>

但我不断收到Red Hat Enterprise Linux Test Page (使用CentOS),它允许子目录,因为我允许/

编辑

这是最终为我工作的Apache配置。 非常感谢Jon Lin的帮助。

<VirtualHost *:80>
    ServerName example.com

    DirectoryIndex index.php
    DocumentRoot /var/www/

    # first, deny all access
    <Directory />
        Order deny,allow
        Deny from all
    </Directory>

    # then start to allow access where required
    <Files index.php>
        Allow from all
    </Files>

    <Directory "/var/www/">
        Allow from all

        Options FollowSymLinks

        RewriteEngine On
        RewriteBase /

        # go directly to index.php if it is accessed
        RewriteRule ^index\.php$ - [L]

        # re-write URL for wp-admin access
        RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

        # re-write wp-* access to route through wp/
        RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) wp/$2 [L]

        # re-write all .php files to route through wp/
        RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ wp/$2 [L]

        # go directly to real files and directories
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^ - [L]

        # respond to all other URLs by passing them through index.php
        RewriteCond %{REQUEST_FILENAME} !-f [OR]
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . index.php [L]

        # deny access if URL doesn't start with these
        RewriteCond %{REQUEST_URI} !^/(index\.php)?$
        RewriteCond %{REQUEST_URI} !^/wp-[^/]+/
        RewriteCond %{REQUEST_URI} !^/templates/
        RewriteRule ^ - [L,F]
    </Directory>
</VirtualHost>

This is an odd configuration, I'll give you that, but I'm looking to deny access to all folders in our system but it must be able to access,

/index.php (Wordpress bootloader)
/wp-*/* (e.g. wp-content, wp-admin, etc.)
/templates/* (some of our templates and custom content)

Everything else is denied (and there are hundreds of folders).

The problem I have is allowing index.php and 2 folders and then denying everything else inside /.

I should be able to accept,

http://example.com/
http://example.com/index.php
http://example.com/wp-content/...
http://example.com/wp-admin/...
http://example.com/wp-includes/...
http://example.com/templates/template.css
http://example.com/templates/subfolder/js/file.js

and reject,

http://example.com/thisIsAFolder
http://example.com/thisIsAnotherFolder

This is what I have,

<VirtualHost *:80>
    ServerName example.com

    DirectoryIndex index.php
    DocumentRoot /var/www/

    <Directory />
        Order deny,allow
        Deny from all
    </Directory>

    <Files index.php>
        Allow from all
    </Files>

    <Directory "/var/www(/|/wp*/|/templates/)">
        Allow from all

        Options FollowSymLinks

        RewriteEngine On
        RewriteBase /

        RewriteRule ^index\.php$ - [L]
        RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d

        RewriteRule ^ - [L]
        RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) wp/$2 [L]
        RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ wp/$2 [L]
        RewriteRule . index.php [L]
    </Directory>
</VirtualHost>

But I continually receive Red Hat Enterprise Linux Test Page (using CentOS) and it allows for sub-directories because I allow /.

EDIT

This is the Apache config that ended up working for me. Big thanks to Jon Lin for the help.

<VirtualHost *:80>
    ServerName example.com

    DirectoryIndex index.php
    DocumentRoot /var/www/

    # first, deny all access
    <Directory />
        Order deny,allow
        Deny from all
    </Directory>

    # then start to allow access where required
    <Files index.php>
        Allow from all
    </Files>

    <Directory "/var/www/">
        Allow from all

        Options FollowSymLinks

        RewriteEngine On
        RewriteBase /

        # go directly to index.php if it is accessed
        RewriteRule ^index\.php$ - [L]

        # re-write URL for wp-admin access
        RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

        # re-write wp-* access to route through wp/
        RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) wp/$2 [L]

        # re-write all .php files to route through wp/
        RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ wp/$2 [L]

        # go directly to real files and directories
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^ - [L]

        # respond to all other URLs by passing them through index.php
        RewriteCond %{REQUEST_FILENAME} !-f [OR]
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . index.php [L]

        # deny access if URL doesn't start with these
        RewriteCond %{REQUEST_URI} !^/(index\.php)?$
        RewriteCond %{REQUEST_URI} !^/wp-[^/]+/
        RewriteCond %{REQUEST_URI} !^/templates/
        RewriteRule ^ - [L,F]
    </Directory>
</VirtualHost>

原文:https://stackoverflow.com/questions/21418830
更新时间:2023-09-01 12:09

最满意答案

首先你不能让“QQmlListProperty”可写。 它只是一个特殊的对象,应该被视为QmlEngine写入的引用。

其次,您只能使用从QObject派生的类型,而QString则不能。

所有JSON对象都在内部由Javascript引擎保留,当有属性赋值时,转换为QVariant(数组具有类型QMetaType :: QVariantList,对象QMetaType :: QVariantMap)。

您应该只使用QVariant,QVariantList或QStringList。


The Qt docs have a sentence that indicates this can't be done:

Generally this constructor should not be used in production code, as a writable QList violates QML's memory management rules.

:(

相关问答

更多
  • 首先你不能让“QQmlListProperty”可写。 它只是一个特殊的对象,应该被视为QmlEngine写入的引用。 其次,您只能使用从QObject派生的类型,而QString则不能。 所有JSON对象都在内部由Javascript引擎保留,当有属性赋值时,转换为QVariant(数组具有类型QMetaType :: QVariantList,对象QMetaType :: QVariantMap)。 您应该只使用QVariant,QVariantList或QStringList。 The Qt docs ...
  • property Item someItem: Item { ... } 该项目不会成为父级,但仍会收集。 明确设置父级将确保它在相应的父级中可见。 请记住, Item::parent是可视父级,而不是实际父级。 因此,即使您明确设置了比属性持有者对象存活时间更长的父级,仍然会收集属性值对象。 这是因为与保持为null的可视父对象不同,“逻辑”父对象将被设置为属性持有者对象。 QML的内存管理是自动的,大多数部件都按预期工作。 要记住两件事: 内存管理器不太愿意释放内存,直到它变得非常必要 在一些“不太正 ...
  • 你可以尝试像这样分配绑定: Component.onCompleted: Singleton.name = Qt.binding(function() { return qmlName }) 它适用于普通的QML对象,但不确定它是否适用于单例类。 无论如何,您可以在“从JavaScript创建属性绑定”一节中阅读有关此方法的更多信息。 You could try to assign the binding like this: Component.onCompleted: Singleton.name = ...
  • 你有一个错字。 该标准将属性定义为writable ,不可writeable 。 修复b定义中的拼写,它完美地运行: b: { value: 'value configured, but writeable', writable: true } You have a typo. The standard defines the property as writable, not writeable. Fix the spelling in the b definition and it ...
  • 我认为在C ++端进行连接并不合适,因为在编译时它不知道在QML中创建的信号,所以可能的解决方案是在QML端进行连接。 下面我将举例说明 main.cpp中 #include #include #include #include class Test: public QObject{ QQuickView *view; Q_OBJECT public: Test(QObject *parent ...
  • “不能将对象赋值给属性”,因为已经有了“data”这样的属性(它是只读的): http://qt-project.org/doc/qt-4.8/qml-item.html#data-prop "Cannot assign object to property" because there is already such property as "data" (and it's read-only): http://qt-project.org/doc/qt-4.8/qml-item.html#data-pr ...
  • 有关属性,可调用方法( 插槽 )和信号的所有信息都由QMetaObject存储在每个QObject中 。 如果您想列出对象中的所有属性: QObject *obj = findObjectMethod(); QMetaObject *meta = obj->metaObject(); int n = meta->propertyCount(); for(int i = 0; i < n; ++i) { qDebug() << "Property: " << meta->property(i)->name ...
  • 首先,将StatedGuiElement创建为QQuickItem子类。 然后你创建一个StatedGuiElement.qml ,导入包含C ++元素的包,在里面创建一个StatedGuiElement {} ,在QML中添加你的状态,然后你就可以在你的项目中使用StatedGuiElement 。 它将是预定义QML额外内容的那个。 这假设元素实际上包含了您需要在C ++中实现的内容。 如果没有那么根本就没有C ++元素是没有意义的。 我不确定旧的C ++状态类是否可以与QML一起使用,可能不是,并且使 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)