2

我只需要重写 url 一个名为gallery. 我想拥有abc.com/photos/gallery/picture/而不是abc.com/photos/gallery/picture.php

.htaccess
index.php
/photos
    /gallery 
        index.php
        picture.php
        functions.php
/videos

这是我的代码,.htaccess但它不起作用。

RewriteEngine on
RewriteRule ^/[.*]/?$ photos/gallery/$1.php#{QUERY_STRING} [NC,L]
4

1 回答 1

2

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /gallery/foo.php to /gallery/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(/+gallery/[^.]+)\.php [NC]
RewriteRule ^ %1 [R=302,L]

## To internally forward /gallery/foo to /gallery/foo.php
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(gallery/.*?)/?$ $1.php [L,NC]
于 2013-02-12T13:56:58.687 回答