【问题标题】:Rewrite URLs not in root directory重写不在根目录中的 URL
【发布时间】:2018-01-04 21:13:55
【问题描述】:

这是我目前所拥有的,它没有像我希望的那样工作:

RewriteEngine On
RewriteRule ^(.*)$ /index.php?id=$1/ [L]

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]

基本上我想在任何地方删除 index.php,并且在一个目录中我也想编辑一个查询字符串,如下所示:

https://example.com/directory/?id=Test

应该是:

https://example.com/directory/Test/

这可能吗?

【问题讨论】:

    标签: php .htaccess web


    【解决方案1】:

    您需要使用 RewriteBase 指令。

    我已经为你准备好了:https://mi-linux.wlv.ac.uk/~in9352/directory/5

    这是我的 .htaccess 中的内容:

    RewriteEngine On
    RewriteBase /~in9352/directory/
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ index.php/?id=$1 [L]
    

    显然你不需要“~in9352”

    这是文档:http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-29
      • 1970-01-01
      相关资源
      最近更新 更多