AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题

问题[.htaccess](ubuntu)

Martin Hope
Daniel Kaplan
Asked: 2021-05-06 10:05:37 +0800 CST

如何在 .htaccess 中完成我的 URL 标头

  • 1

我有一个www.example.com在 Apache 上运行的网站。

也许有人通过example.com, or www.example.com, or http://example.com, or even找到我http://www.example.com。

我可以使用重写规则,.htaccess以便无论它们到达example.com,URL 都完全充实到http://www.example.com?

.htaccess
  • 1 个回答
  • 107 Views
Martin Hope
Martin AJ
Asked: 2020-09-14 04:07:14 +0800 CST

如何使文件只能通过自己的服务器访问?

  • 3

我已将其添加到 .htaccess位于项目根目录的文件中:

<Files *.php>
    Require host lamtakam.test lamtakam.com
    Require ip ::1 95.216.xx.xx
</Files>

我曾经xx.xx将我的真实 ip 隐藏在公共社区中,实际上,有数字而不是xs。

现在我需要每天crontab从同一台服务器调用一个文件(使用 cron 作业),如下所示:

0 22 * * * wget /path/to/file.php

但我得到这个错误:

--2020-09-13 13:33:55--  https://lamtakam.com/path/to/file.php
Resolving lamtakam.com (lamtakam.com)... 104.31.74.192, 172.67.174.239, 104.31.75.192, ...
Connecting to lamtakam.com (lamtakam.com)|104.31.74.192|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2020-09-13 13:33:55 ERROR 403: Forbidden.

注意:我使用 Cloudflare,这些 IP 属于它:104.31.74.192, 172.67.174.239, 104.31.75.192

知道如何file.php从同一台服务器访问它吗?(而不是来自其他任何地方)

dns apache2 .htaccess
  • 1 个回答
  • 134 Views
Martin Hope
Felipe S.
Asked: 2020-08-02 11:51:23 +0800 CST

.htaccess 不工作(apache2 | ubuntu 18.04)

  • 5

伙计们,网站运行良好,只是文件 .htaccess 不起作用,我用谷歌搜索了很多,已经启用a2enmod rewrite并尝试了很多东西,但是没有用。

obs:我以网站 example.com 为例

我/etc/apache2/sites-available/000-default.conf是这样的:

<VirtualHost *:80>

    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

这就是我/etc/apache2/apache2.conf的:

<Directory />
        Options FollowSymLinks
        AllowOverride All
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

这就是我的 .htaccess 的样子:

#DISALOW DIRECTORY LISTING
Options -Indexes

ErrorDocument 400 /.error.php
ErrorDocument 401 /.error.php
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
ErrorDocument 405 /.error.php
ErrorDocument 408 /.error.php
ErrorDocument 414 /.error.php
ErrorDocument 500 /500.php
ErrorDocument 502 /.error.php
ErrorDocument 504 /.error.php

但它不是不允许目录列表,也不是在404.php找不到页面时显示内容。

apache2 .htaccess
  • 1 个回答
  • 5341 Views
Martin Hope
ahmedg
Asked: 2020-07-09 21:50:58 +0800 CST

如何将 .htaccess 代码添加到 apache2.conf?

  • 1

我想将我的.htaccess代码添加到/etc/apache2/apache2.conf.

我想结合这些:

.htaccess文件。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>

/etc/apahce2/apache2.conf文件。

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>



问题是我不知道在哪里添加htaccess代码。如何合并这些文件?
我正在使用Ubuntu 18.04.
提前致谢!

server apache2 18.04 .htaccess
  • 1 个回答
  • 425 Views
Martin Hope
Monkeybus
Asked: 2019-12-26 19:10:18 +0800 CST

htaccess 重定向问题

  • 0

所以,

假设我在foo.com/a上有我的购物车

我想将购物者重定向到foo.com/b

在foo.com我的.htaccess包含

RedirectMatch 302 ^/(index\.html)?$ foo.com/b

但是人们仍然登陆foo.com/a(如果他们键入它/将其添加为书签)它不会重定向。仅当他们登陆foo.com时才会重定向

我确定这是一个微不足道的问题。任何人都可以帮忙吗?

以后再和大家聊。

redirect .htaccess
  • 2 个回答
  • 127 Views
Martin Hope
Doug Smythies
Asked: 2019-06-21 13:39:52 +0800 CST

Apache Web 服务器 - 如何去除语言扩展

  • 2

这个问题与在 help.ubuntu.com 上发布 Ubuntu Serverguide 有关。对于 20.04 LTS 周期,Ubuntu Serverguide 的源代码工作流程(好吧可能)会有重大变化。目前,此迁移不考虑翻译。我们最好的反馈是服务器管理员类型更喜欢英语,即使它不是他们的第一语言。在决定变得不可逆之前,我们希望通过仅用美国英语发布 18.04 Ubuntu Serverguide 的下一个版本来测试它。一切准备就绪,除了一个问题:

我们肯定知道,语言扩展名中存在许多链接、书签等。例子:

https://help.ubuntu.com/lts/serverguide/networking.html.en-CA

我们希望该场景返回此页面:

https://help.ubuntu.com/lts/serverguide/networking.html

因为特定语言版本将不再存在,但返回 404 Not Found 错误是不可取的。

.htaccess 文件的当前版本(已注释掉以前的尝试)是:

# unable to make below method work.
#RedirectMatch permanent ^(*\.html)\.*$ $1
#
# enable rewriting
RewriteEngine on
#RewriteRule ^(*\.html)\.*$ $1 [R=301, L]
#RewriteRule ^(*\.html)\.*$ $1
RewriteRule ^(*\.html)\.*$ $1 [PT]
#RewriteRule ^(*.html).*$ $1

导致:

500 Internal Server Error

到客户端,这在测试服务器日志中:

[Thu Jun 20 11:57:07.647838 2019] [core:alert] [pid 16079] [client 192.168.111.101:62992] /home/doug/public_html/linux/ubuntu-docs/help.ubuntu.com/dev/lts/serverguide/.htaccess: RewriteRule: cannot compile regular expression '^(*\\.html)\\.*$', referer: http://my-test-website/~doug/linux/ubuntu-docs/help.ubuntu.com/dev/index.html
[Thu Jun 20 14:19:27.360334 2019] [core:alert] [pid 16079] [client 192.168.111.101:63908] /home/doug/public_html/linux/ubuntu-docs/help.ubuntu.com/dev/lts/serverguide/.htaccess: RewriteRule: cannot compile regular expression '^(*\\.html)\\.*$', referer: http://my-test-website/~doug/linux/ubuntu-docs/help.ubuntu.com/dev/index.html

请注意,当前尝试使用语言扩展的通配符。如果这是不可能的,那么语言列表是:

ace ar ast be bg bn bs ca cs da de el en en_AU en_CA en_GB eo es et eu fa fi fr gl gu he hr hu id is it ja km ko ku lo lt lv mk ms nb nl oc pl ps pt_BR pt ro ru sk sl sq sr sv th tl tr ug uk ur vi zh_CN zh_TW

有人可以帮忙吗?

server apache2 language .htaccess mod-rewrite
  • 1 个回答
  • 110 Views
Martin Hope
Brendan
Asked: 2019-03-13 10:42:15 +0800 CST

.htaccess 文件中的多个重定向 - 执行第一个

  • 0

我正在尝试使用 .htaccess 将表达式引擎中的单个页面重定向到另一个站点的页面。我们的 .htaccess 文件具有大量其他重写规则和重写条件,以确保表达式引擎站点有效运行。

我在 .htaccess 文件的顶部有这个 RedirectMatch。

RedirectMatch (?i)^/my-page https://www.differentsite.com/my-page

重定向可以发送到新站点,除了它在目标服务器上我的网址末尾添加了一个额外的“?/我的页面”。所以它以“ https://www.differentsite.com/my-page?/my-page ”的形式出现

我相信这是因为 .htaccess 文件中的一些其他规则在此规则之下附加/尝试到 URL 的某些额外部分。

如何确保使用 .htaccess 只执行第一行?

此外,有没有一种方法可以通过某种类型的访问/日志文件测试 .htaccess URL 在发送之前尝试发送的确切内容?

谢谢!

server apache2 .htaccess
  • 2 个回答
  • 1038 Views
Martin Hope
newcat1000
Asked: 2019-01-08 13:58:25 +0800 CST

服务器版本从 16.04 升级到 18.04 后无法访问我的网站(droplet)

  • 1

当我输入我的域时,我得到:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.
Apache/2.4.29 (Ubuntu) Server at www.mywebsite.net Port 443

在我的错误日志中,我发现了这个:

/var/www/html/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration, referer: https://www.google.lv/

我的 PHP 版本运行 php -v

PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

我的 .htaccess 中有这个

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^165\.227\.175\.218$
RewriteRule ^(.*)$ http://www.mywebsite.net/$1 [L,R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Wordfence WAF
<IfModule mod_php7.c>
php_value auto_prepend_file '/var/www/html/mywebsite/public_html/wordfence-waf.php'

在 /var/www/html/mywebsite/public_html/wordfence-waf.php 我有这个:

<?php
// Before removing this file, please verify the PHP ini setting          `auto_prepend_file` does not point to this.

 if (file_exists('/var/www/html/mywebsite/public_html/wp-content/plugins /wordfence/waf/bootstrap.php')) {
define("WFWAF_LOG_PATH", '/var/www/html/mywebsite/public_html/wp-content  /wflogs/');
include_once '/var/www/html/mywebsite/public_html/wp-content/plugins/wordfence/waf/bootstrap.php';
}
?>    

我试过了:

sudo a2enmod rewrite && sudo service apache2 restart
/etc/host.conf: line 3: bad command `nospoof on'
Module rewrite already enabled
/etc/host.conf: line 3: bad command `nospoof on'

/usr/sbin/apache2 -V | grep MPM

[Tue Jan 08 12:05:13.506757 2019] [core:warn] [pid 6361] AH00111: Config   variabl e ${APACHE_LOCK_DIR} is not defined
[Tue Jan 08 12:05:13.506990 2019] [core:warn] [pid 6361] AH00111: Config variabl e ${APACHE_PID_FILE} is not defined
[Tue Jan 08 12:05:13.507254 2019] [core:warn] [pid 6361] AH00111: Config variabl e ${APACHE_RUN_USER} is not defined
[Tue Jan 08 12:05:13.507358 2019] [core:warn] [pid 6361] AH00111: Config variabl e ${APACHE_RUN_GROUP} is not defined
[Tue Jan 08 12:05:13.507469 2019] [core:warn] [pid 6361] AH00111: Config variabl e ${APACHE_LOG_DIR} is not defined
[Tue Jan 08 12:05:13.514596 2019] [core:warn] [pid 6361] AH00111: Config variabl e ${APACHE_RUN_DIR} is not defined
[Tue Jan 08 12:05:13.515068 2019] [core:warn] [pid 6361] AH00111: Config variabl e ${APACHE_LOG_DIR} is not defined
Server MPM: prefork

试图看看这个链接是否可以帮助我。

我跑了:sudo apachectl -t得到了syntax ok。我无法运行sudo apache2 -X -f /etc/apache2/httpd.conf,因为我没有httpd.conf文件。如果我跑:service apachectl start我得到Failed to start apachectl.service: Unit apachectl.service not found.

这是我的/etc/apache2/envvars

# envvars - default environment variables for apache2ctl

# this won't be correct after changing uid
unset HOME

# for supporting multiple apache2 instances
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
else
SUFFIX=
fi

# Since there is no sane way to get the parsed apache2 config in     scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
# temporary state file location. This might be changed to /run in Wheezy 1
export APACHE_PID_FILE=/var/run/apache2$SUFFIX/apache2.pid
export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX
# Only /var/log/apache2 is handled by /etc/logrotate.d/apache2.
export APACHE_LOG_DIR=/var/log/apache2$SUFFIX

## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:
#. /etc/default/locale

export LANG

## The command to get the status for 'apache2ctl status'.
## Some packages providing 'www-browser' need '--dump' instead of '-dump'.
#export APACHE_LYNX='www-browser -dump'

## If you need a higher file descriptor limit, uncomment and adjust the
## following line (default is 8192):
#APACHE_ULIMIT_MAX_FILES='ulimit -n 65536'

## If you would like to pass arguments to the web server, add them     below
## to the APACHE_ARGUMENTS environment.
#export APACHE_ARGUMENTS=''

## Enable the debug mode for maintainer scripts.
## This will produce a verbose output on package installations of web     server modules and web application
## installations which interact with Apache
#export APACHE2_MAINTSCRIPT_DEBUG=1

任何有关如何再次访问我的网站的帮助将不胜感激。我可以通过 WinSCP 和 Putty 进行 SSH 访问。

server do-release-upgrade apache2.4 php7 .htaccess
  • 1 个回答
  • 1067 Views
Martin Hope
Haroon
Asked: 2019-01-06 16:53:13 +0800 CST

Apache2:通过匹配一些表达式,从 Basic Auth 中排除所有其余 api Request_URIs

  • 1

我已经Basic Auth为浏览器身份验证设置了一个 Opencart 项目,以仅允许访问相关用户。现在,I need to use REST API for a mobile app. 当我从 API 调用端点以从 Opnecart 项目获取一些详细信息时,它需要从 API 生成 access_token,并且通过在每个请求中使用该 access_token,我可以从 API 获取详细信息。问题是我为项目设置的基本身份验证,因此我无法访问 API,因为我只能使用 1 种方法访问 API,即 GET 方法从 opencart 获取详细信息,我不能使用 2 种方法,即Auth Header and GET methods. 所以,what I am trying to do is to disable Basic Auth if the Request_URI includes api calls.

到目前为止,我对项目的 vhost 所做的尝试如下,但这一切都没有奏效。

从以下问题的已接受答案中得到了这个想法,但它并没有为我锻炼。 https://stackoverflow.com/questions/8978080/htaccess-exclude-one-url-from-basic-auth?answertab=votes#tab-top

<Directory /var/www/html/projectexample>
 AllowOverride All        
 # Auth stuff
 AuthName "Authentication Required"
 AuthType Basic
 AuthUserFile /etc/apache2/.htpasswd
 Order allow,deny
 Deny from all
 Satisfy any
 <RequireAny>
    <RequireAll>
        Require expr %{REQUEST_URI} =~ m#^/api/rest/.*#
    </RequireAll>
    Require valid-user
 </RequireAny>
</Directory>

我也尝试过使用 SetEnvIf 环境变量,如下所示,但它也没有锻炼。

<Directory /var/www/html/projectexample>
  AllowOverride All        
  # Auth stuff
  AuthName "Authentication Required"
  AuthType Basic
  AuthUserFile /etc/apache2/.htpasswd
  SetEnvIf Request_URI "^/api/*" allow=1
  #SetEnvIf Request_URI "^/(api/*)" allow=1
  Order allow,deny
  Require valid-user
  Allow from env=allow
  Deny from env!=allow
  Satisfy any
</Directory>

请问有什么解决办法吗?

server authentication apache2 18.04 .htaccess
  • 2 个回答
  • 3638 Views
Martin Hope
John Doe
Asked: 2018-09-18 01:13:31 +0800 CST

将 Apache VirtualHosts 限制在自己的目录中

  • 1

我在 Ubuntu 16.04 和 18.04 上运行 Apache,并且我已将其配置为接受来自多个域的连接。这些站点都存储在/var/www/html这样的位置:

example.com
sub.example.com
sample.com
...

其中一些网站正在进行中,我已经为在这些网站上工作的人创建了用户帐户。对于这样的站点,我mount --bind将站点的文件夹添加到用户的主文件夹,它们被 chroot 到。因此,如果用户john正在处理sample.com,他们将看到该文件夹​​,就像/sample.com他们登录时一样。

显然,这个想法是将用户限制在他们负责的项目中。但是,由于 PHP 是使用 运行的www-data,所以/var/www/html任何用户都可以在/var/www/html使用 PHP 时修改任何文件。

有没有办法通过.htaccess或任何其他方式将PHP锁定在每个站点的文件夹中,以便只允许修改其站点文件夹内的文件夹?IE 如果我在里面运行一个 PHP 脚本sample.com,该脚本应该不能读取或写入上面的文件夹sample.com。

server permissions php apache2 .htaccess
  • 1 个回答
  • 123 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve