【问题标题】:Removing .php from url's in the htaccess, not i can't install wordpress on a sub folder从htaccess中的url中删除.php,不是我不能在子文件夹上安装wordpress
【发布时间】:2012-03-23 22:15:39
【问题描述】:

我的网站一直在使用以下代码从 URL 的末尾删除 .php

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^/]+)/$ $1.php

RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

我现在已经在文件夹的/clients/ 中安装了 wordpress,但它无法正常工作,因为它也在重写 wordpress,我不希望它这样做,但我不确定如何修复上面的代码来阻止它发生在 sup 文件夹中。

完整的htaccess

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.

RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^/]+)/$ $1.php

RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$

RewriteRule (.*)$ /$1/ [R=301,L]

# compress text, html, javascript, css, xml:

AddOutputFilterByType DEFLATE text/plain

AddOutputFilterByType DEFLATE text/html

AddOutputFilterByType DEFLATE text/xml

AddOutputFilterByType DEFLATE text/css

AddOutputFilterByType DEFLATE application/xml

AddOutputFilterByType DEFLATE application/xhtml+xml

AddOutputFilterByType DEFLATE application/rss+xml

AddOutputFilterByType DEFLATE application/javascript

AddOutputFilterByType DEFLATE application/x-javascript


# Or, compress certain file types by extension:

<FilesMatch "\.(php|html|css|js)$"> 

SetOutputFilter DEFLATE

</FilesMatch>

【问题讨论】:

    标签: apache wordpress .htaccess mod-rewrite


    【解决方案1】:

    首先,您的重写代码看起来不正确。这是将跳过 /clients/ URI 重写的固定代码。

    ## hide .php extension
    # To externally redirect /dir/foo.php to /dir/foo
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^(?!clients/).*$ %1 [R,L,NC]
    
    ## To internally redirect /dir/foo to /dir/foo.php
    RewriteCond %{REQUEST_FILENAME}.php -f [NC]
    RewriteRule ^(?!clients/).*$ %{REQUEST_URI}.php [L,NC]
    

    【讨论】:

    • 您好感谢您的代码,但它会导致原始代码将删除 .php 的所有页面上出现 404 错误
    • 你能在这里发布你的完整 .htaccess 和导致 404 的 URI 吗?
    • 另外让你知道我已经测试了上面的代码并且它在这里工作正常。
    【解决方案2】:

    在 /clients/ 文件夹中添加一个 .htaccess 文件,其中包含以下内容:-

    RewriteEngine off
    

    在里面。这会关闭该文件夹及其子文件夹的 mod_rewrite。

    【讨论】:

      猜你喜欢
      • 2014-04-13
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      • 2015-01-21
      • 1970-01-01
      相关资源
      最近更新 更多