Articles of mod rewrite

根据部分用户代理string阻止networking请求 – 不工作

我试图阻止networking请求的基础上,如果他们包含任何一组string。 就我自己的知识和网上search而言,我所知道的是正确的。 但是,我仍然在访问日志中看到这些types的请求。 如果请求在Apacheconfiguration中被阻塞,访问日志条目是否还会被创build? 或者是我在我的VHOST定义中有错? RewriteEngine On Options +FollowSymLinks RewriteCond %{HTTP_USER_AGENT} ^.*(icevikatam|AhrefsBot|spbot|MJ12|majestic12|Ahrefs).*$ [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^.*(Semrush|SISTRIX|80legs|HTTrack|Xenu|dataprovider).*$ [NC] RewriteRule .* – [F,L] 我的Web服务器是IBM i的Apache 2.4。

.htaccess不能redirect的URL没有扩展名

我有一些url(从外部链接),没有扩展名,例如 www.example.com/main 最初在服务器的根目录中有main.htm和main.html文件。 但是,一个 RewriteRule ^main$ main.html [L,R=301] 不起作用。 在服务器根目录下没有文件夹main/也没有名为main的文件。 在.htaccess文件中还有其他一些条目可以工作,所以我确信RewriteMod是有效的并且正在工作。 我还重写了可redirect的拼写错误规则(指向www.example.com/xyz)的链接www.example.com/xyz) 。 RewriteRule ^xyz\)$ xyz/index.html [L,R=301] 有趣的是, www.example.com/main main.de.html URL在浏览器中不会改变(浏览器栏中的URL不会改变(与redirect一样)),但页面会显示文件main.de.html 。 如果我创build了一个名为main.da.html的文件,它会显示该内容(但仅在apache重新启动后)。 我无法弄清楚它是如何到达那里或如何将其redirect到main.html 。

拒绝所有的文件夹,除了一些PHP文件

我有一个脚本来设置下载主机的一些限制。 这个脚本给了我一些文件(index.php|dl.php|config.php) ,我必须把它们放在我的下载主机上。 脚本也有这些htaccess代码: Order allow,deny Deny from All <FilesMatch "^(index\.php)?$"> Allow from All </FilesMatch> <FilesMatch "^(dl\.php)?$"> Allow from All </FilesMatch> 但我的networking服务器是NGINX。 我应该把什么重写代码放在nginx.conf? 顺便说一下,我想对vip文件夹mysomain.com/vip设置限制。 我把(index.php | dl.php | config.php)`放在上面。

重写规则以重新编写旧的到漂亮的URL

我希望将https://www.example.com/somePage.php?id=1234redirect到https://www.example.com/tool/1234 (以便传统链接和书签工作)。 我觉得我很接近,但这似乎不起作用… RewriteRule ^somePage.php?toolid=([0-9]+)$ /tool/$1 [R=301,L] 这里有什么问题?

如何使example.com/about显示example.com/about.html? (Apache2的)

尝试使用example.com/about show example.com/about.html,而不必将url更改为/about.html时,最佳select是什么? 现在我正在尝试下面的代码,它只是返回一个404错误。 RewriteRule ^/about$ https://example.com/about.html [R=301,L] 编辑#1 W3DK我目前有多视图启用,但我仍然得到一个404错误。 这是我当前在VirtualHost中的当前设置 <Directory /var/www/public_html> Options All +MultiViews AllowOverride All Order allow,deny allow from all </Directory>

nginx如何重写除指定扩展名以外的所有url?

我试图将rewrite rules从.htaccess文件转换为nginxconfiguration。 作为移动网站到NGINXnetworking服务器的一部分。 这里是从.htaccess文件重写规则 Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_URI} !\.php$ RewriteCond %{REQUEST_URI} !\.gif$ RewriteCond %{REQUEST_URI} !\.jp?g$ RewriteCond %{REQUEST_URI} !\.png$ RewriteCond %{REQUEST_URI} !\.css$ RewriteCond %{REQUEST_URI} !\.js$ RewriteCond %{REQUEST_URI} !\.html$ RewriteCond %{REQUEST_URI} !\.xhtml$ RewriteCond %{REQUEST_URI} !\.htm$ RewriteCond %{REQUEST_URI} !\.ico$ RewriteRule (.*) index.php [L] RewriteRule (.*).html index.php [L] 我当前的nginx config 。 server { listen 80; server_name example.com; […]

使用.htaccess文件限制可用的文件types上传

我知道第一行,这是显而易见的,对于第二行,我认为它只允许这些less数扩展名,第三行我假设禁止任何其他文件types。 我不知道,如果我的假设是正确的,如果给定的htaccess文件是禁止上传不需要的其他文件types,如PHP或ZIP,或EXE … RewriteEngine on RewriteCond %{REQUEST_FILENAME} !(\.jpg|\.jpeg|\.pdf|\.png) RewriteRule ^(.*)$ – [F]

如何有2个域名指向同一个网站,一个http和另一个https

我目前已经改写在example.com工作,整个网站是HTTPS,使用这个: RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] 我需要很多文件在这个完全相同的网站上,可以通过第二个域名访问,并通过HTTP,例如: http://example.net/files/…. 我尝试添加example.net作为ServerAlias但当然这只是redirect,然后重写到https://example.net/files 我从互联网复制了重写规则,并且不确定修改它的正确方法。 我正在按照改写重写规则的思路来思考: RewriteRule ^example.com/?(.*) https://example.com/$1 [R,L] 所以只有在包含example.com URL才会被重写。那么我是否需要为TLD域自身重写规则,而不是通配符条目? 请有人可以帮助正确的方式来实现这一点,以便对ServerAlias ( example.net )的请求不被重写?

Apache重写URL以被AliasMatch捕获

我需要mod_rewrite重新映射传入的URL,以便它被AliasMatch捕获。 RewriteCond %{REQUEST_URI} ^/app/(.*)$ RewriteRule ^/app/(.*) ^/dev-dave/app/$1 RewriteCond %{REQUEST_URI} ^/static/(.*)$ RewriteRule ^/static/(.*) ^/dev-dave/static/$1 AliasMatch ^/(.*)/static/(.*)$ /var/www/html/cosmos/$1/dist/static/$2 AliasMatch ^/(.*)/app/(.*)$ /var/www/html/cosmos/$1/dist/index.html <Directory /var/www/html/cosmos> AllowOverride None Require all granted <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d </IfModule> </Directory> 这可能吗? 我无法得到这个工作。

将所有裸体子文件夹redirect到子文件夹名称/ public /

我正在尝试做一个.htaccess所有顶级子文件夹redirect/重写到一个子文件夹。 例如,我的目录结构如下所示 /public_html /site1 /public /site2 /public /site3 /public 我想任何人去example.com/site1/来从example.com/site1/public文件服务,但我不希望URL必须public 。 这是我所尝试的: RewriteEngine On #RewriteRule /(.?)/ /$1/public/ [L]