【发布时间】:2011-04-15 18:09:24
【问题描述】:
在 LAMP 服务器上,我想要 URL
http://example.com/index.php被重写为简单的
http://example.com
我目前的.htaccess文件如下...
IndexIgnore *
ErrorDocument 400 /index.php?module=error&action=error
ErrorDocument 401 /index.php?module=error&action=error
ErrorDocument 403 /index.php?module=error&action=error
ErrorDocument 404 /index.php?module=error&action=error
ErrorDocument 500 /index.php?module=error&action=error
RedirectMatch 301 ^/media/$ /
RedirectMatch 301 ^/media/documents/$ /
RedirectMatch 301 ^/media/graphics/$ /
RedirectMatch 301 ^/media/photos/$ /
RedirectMatch 301 ^/library/$ /
RedirectMatch 301 ^/library/css/$ /
RedirectMatch 301 ^/library/ht/$ /
RedirectMatch 301 ^/library/js/$ /
RedirectMatch 301 ^/library/php/$ /
RewriteEngine on
RewriteBase /
RewriteRule ^home$ /index.php?module=home&action=frontpage
RewriteRule ^home/$ /index.php?module=home&action=frontpage
RewriteRule ^home/([^/\.]+)$ /index.php?module=home&action=$1
RewriteRule ^home/([^/\.]+)/$ /index.php?module=home&action=$1
RewriteRule ^cv$ /index.php?module=home&action=cv
RewriteRule ^cv/$ /index.php?module=home&action=cv
RewriteRule ^release$ /index.php?module=release&action=release
RewriteRule ^release/$ /index.php?module=release&action=release
RewriteRule ^photos$ /index.php?module=gallery&action=album&album=general
RewriteRule ^photos/$ /index.php?module=gallery&action=album&album=general
RewriteRule ^gallery$ /index.php?module=gallery&action=album&album=general
RewriteRule ^gallery/$ /index.php?module=gallery&action=album&album=general
RewriteRule ^gallery/([^/\.]+)$ /index.php?module=gallery&action=album&album=$1
RewriteRule ^gallery/([^/\.]+)/$ /index.php?module=gallery&action=album&album=$1
RewriteRule ^gallery/([^/\.]+)/([^/\.]+)$ /index.php?module=gallery&action=album&album=$1$&page=$2
RewriteRule ^gallery/([^/\.]+)/([^/\.]+)/$ /index.php?module=gallery&action=album&album=$1$&page=$2
RewriteRule ^gallery/([^/\.]+)/([^/\.]+)/([^/\.]+)$ /index.php?module=gallery&action=item&album=$1$&page=$2&item=$3
RewriteRule ^gallery/([^/\.]+)/([^/\.]+)/([^/\.]+)/$ /index.php?module=gallery&action=item&album=$1$&page=$2&page=$3
RewriteRule ^handouts$ /index.php?module=home&action=handouts
RewriteRule ^handouts/$ /index.php?module=home&action=handouts
RewriteRule ^links$ /index.php?module=home&action=links
RewriteRule ^links/$ /index.php?module=home&action=links
RewriteRule ^contact$ /index.php?module=home&action=contact
RewriteRule ^contact/$ /index.php?module=home&action=contact
RewriteRule ^login$ /index.php?module=authentication&action=login
RewriteRule ^login/$ /index.php?module=authentication&action=login
RewriteRule ^logout$ /index.php?module=authentication&action=logout
RewriteRule ^logout/$ /index.php?module=authentication&action=logout
RewriteRule ^copyright$ /index.php?module=home&action=copyright
RewriteRule ^copyright/$ /index.php?module=home&action=copyright
RewriteRule ^error$ /index.php?module=error&action=error
RewriteRule ^error/$ /index.php?module=error&action=error
我应该如何编辑我的 .htaccess 文件来完成这个基本的重写?此外,对于我的 .htaccess 代码的任何其他反馈,我们将不胜感激。
提前致谢!
【问题讨论】:
-
我这辈子从没见过这么浓密的 .htaccess 文件。是不是真的写了那么多乱七八糟的,不知道怎么添加这个简单的重写规则?
-
我确实写过,哈哈,但是我遇到了重定向循环错误的问题。也许它太浓密了!大声笑有关如何使代码更高效的任何建议?
标签: php apache url .htaccess lamp