【问题标题】:rewrite sub folder url query string重写子文件夹url查询字符串
【发布时间】:2018-04-06 04:26:04
【问题描述】:

我是网络开发新手。

以下 Htaccess 代码在根目录文件中运行良好。当我们尝试重写子文件夹 /test/downloadh.php 中的文件时。当我更改以下代码时,我们将无法获取根文件链接不起作用。

RewriteEngine on
RewriteBase /test/

请您建议我们,如何获取网址

http://example.com/test/downloadh/the-house-on-the-borderland

http://example.com/test/downloadh.php?id=the-house-on-the-borderland

工作代码:-

    # disable directory browsing
    Options -Indexes

    AddDefaultCharset UTF-8
    FileETag MTime Size
    Options +FollowSymLinks -MultiViews

    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+album\.php\?Id=([^\s&]+) [NC]
    RewriteRule ^ album/%1? [R=301,L]
    RewriteRule ^album/([^/]+)/?$ album.php?Id=$1 [L,QSA]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+download\.php\?id=([^\s&]+) [NC]
    RewriteRule ^ download/%1? [R=301,L]
    RewriteRule ^download/([^/]+)/?$ download.php?id=$1 [L,QSA]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+downloada\.php\?linkb=([^\s&]+) [NC]
    RewriteRule ^ downloada/%1? [R=301,L]
    RewriteRule ^downloada/([^/]+)/?$ downloada.php?linkb=$1 [L,QSA]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:downloadb\.php)?\?mlink=([^\s]+)&linkb=([^\s]+)? [NC]
    RewriteRule ^ downloadb/%1%2? [R=301,L]
    RewriteRule ^downloadb/([^/]+)/([^/]+)/?$ downloadb.php?mlink=$1&linkb=$2 [L,QSA]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:songs\.php)?\?id=([^\s]+)&linkb=([^\s]+)? [NC]
    RewriteRule ^ songs/%1/%2? [R=301]
    RewriteRule ^songs/([^/]+)/([^/]+)/?$ songs.php?id=$1&linkb=$2 [L,QSA]

    # CUSTOM ERRORPAGE
    ErrorDocument 401 /error/test.php
    ErrorDocument 403 /error/test.php
    ErrorDocument 404 /error/test.php
    ErrorDocument 500 /error/test.php

错误代码:-

RewriteCond %{THE_REQUEST} /downloadh(?:\.php)?\?id=([^\s&]+)\s [NC]
RewriteRule ^ downloadh/%1/? [R=302,L,NE]
RewriteRule ^downloadh/([^/]+)/?$ downloadh.php?id=$1 [NC,L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /test/downloadh.php\?id=([^\s&]+) [NC]
RewriteRule ^test/downloadh\.php /%1? [R=301,L,NE]
RewriteRule ^downloadh/([^/]+)/?$ /test/downloadh.php?id=$1 [L,QSA]

【问题讨论】:

  • 你想同时重定向 /test/downloadh.php 和 /downloahd.php 请求还是只重定向 /test/downloadh.php ?
  • /test/downloadh.php 仅限 url 文件。

标签: .htaccess


【解决方案1】:

试试这个代码:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/(test/downloadh)\.php\?id=(.+)\sHTTP.*$ [NC]
RewriteRule ^        %1/%2? [L,R=301]
RewriteRule ^test/downloadh/([^/]+)/?$ test/downloadh.php?id=$1 [L]

【讨论】:

  • 太棒了。你真的救了我。再次感谢您提供宝贵的帮助。
  • 非常感谢您花时间帮助我。非常感谢,继续努力。
  • @vijaybharathi 很高兴为您提供帮助,不客气,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
  • 2011-08-02
  • 2012-01-18
  • 1970-01-01
  • 1970-01-01
  • 2016-07-30
相关资源
最近更新 更多