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 / 问题

问题[mod-rewrite](ubuntu)

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
GHOST
Asked: 2018-12-18 23:05:18 +0800 CST

Apache 重写 URL 在 vhost.conf 中不起作用

  • 0

这是我的 vhost.conf

<VirtualHost *:80>
<files xmlrpc.php>
      order allow,deny
      deny from all
    </files>
    ServerName www.myserver.com
    ServerAlias myserver.com

    DocumentRoot /var/www/vhosts/www.myserver.com
    <Directory /var/www/vhosts/www.myserver.com>
   Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
# AllowOverride None
        #Order Allow,Deny
        #Allow from All
        #Deny from 124.43.19.230

        <IfModule mod_rewrite.c>
          RewriteEngine On
          RewriteBase /
          RewriteRule ^index\.php$ - [L]
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule . /index.php [L]

# Restrict access to PHP files from plugin and theme directories
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/file/to/exclude\.php
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/directory/to/exclude/
RewriteRule wp-content/plugins/(.*\.php)$ - [R=404,L]
RewriteCond %{REQUEST_URI} !^/wp-content/themes/file/to/exclude\.php
RewriteCond %{REQUEST_URI} !^/wp-content/themes/directory/to/exclude/
RewriteRule wp-content/themes/(.*\.php)$ - [R=404,L]
        </IfModule>
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/file/to/exclude\.php
RewriteCond %{REQUEST_URI} !^/wp-content/plugins/directory/to/exclude/
RewriteRule wp-content/plugins/(.*\.php)$ - [R=404,L]
RewriteCond %{REQUEST_URI} !^/wp-content/themes/file/to/exclude\.php
RewriteCond %{REQUEST_URI} !^/wp-content/themes/directory/to/exclude/
RewriteRule wp-content/themes/(.*\.php)$ - [R=404,L]
</Directory>
</VirtualHost>

在浏览器中输入 www.myserver.com 时,它会转到我的根目录并获取 index.php

但是当我输入 myserver.com 时,它会转到默认的 Apache 网页(index.html)加载

所以我添加这一行进行重写

</VirtualHost>
 <VirtualHost *:80>
      ServerName myswever.com
      ServerAlias *.myswever.com
      Redirect permanent / https://www.myswever.com/
    </VirtualHost>

但它不起作用它是一个word-press网站如何重新连接url

当某些类型 myswever.com 它应该加载 www.myswever.com

server php apache2 mod-rewrite
  • 1 个回答
  • 1204 Views
Martin Hope
Anand Huded
Asked: 2018-06-12 21:56:42 +0800 CST

Apache Rewrite 模块无法正常工作

  • 0

继续在 Ubuntu 16.04 LTS 上遇到错误。

404 Not Found
The requested URL /application/templates was not found on this server.

Apache/2.4.18 (Ubuntu) Server at 00.0.0.00 Port 80

在 error.log 中显示:

No such file or directory in /var/www/html/aplication/api.php on line 228

以下是我目前的重写规则:

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
#RewriteRule ^([a-z]+)\/?$ $1.php [NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
#RewriteRule ^([a-z]+)\/?$ $1.html [NC]

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?a=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?a=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?a=$1&b=$2&c=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?a=$1&b=$2&c=$3

</IfModule>

tail -f var/log/apache2/error.log 的输出

[Thu Jun 14 10:30:50.138694 2018] [:error] [pid 7150] [client 172.29.9.57:38776] PHP Stack trace:
[Thu Jun 14 10:30:50.138704 2018] [:error] [pid 7150] [client 172.29.9.57:38776] PHP   1. {main}() /var/www/html/TestCopy_Report1/index.php:0

查找的输出:

sudo find / -iname api.php
 find: ‘/run/user/1000/gvfs’: Permission denied
 /var/www/html/application/api.php
 /var/www/html/test1/api.php
 /var/www/html/test2/api.php
 /var/www/html/test3/api.php
 /var/www/html/test4/api.php
 /var/www/html/test5/api.php
apache2 mod-rewrite
  • 2 个回答
  • 7613 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