mod_rewrite玩家和网站页面的根URL

时间:2015-03-11 19:57:59

标签: apache .htaccess mod-rewrite

我的播放器名称来自根目录something.com/username我还有一个ID用于加载配置文件表单ID而不是something.com/id/1234,但我也希望能够加载我的页面index.php?page = about from something.com/about只有大约6-10页,所以我可以在htaccess中手动创建。 我还需要我的搜索页面来处理参数something.com/search/searchterms

这是我目前的htaccess文件。

# BEGIN Pretty Url's
Options -Indexes

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Rewrite all urls to use slash at the end.
#RewriteRule ^(.*[^/])$ ./$1/ [L,R=301]
RewriteRule ^([_A-Z0-9a-z-+\.]+)/?$ ./pages/player.php?p=$1 [L]
RewriteRule ^id/([_0-9-+\.]+)/?$ ./pages/player.php?id=$1 [L]
# END Pretty Url's

# BEGIN Security Features
# Deny config.php
<files config.php>
  order allow,deny
  deny from all
</files>

# Deny all .hta* files
<files ~ "^.*\.([Hh][Tt][Aa])">
  order allow,deny
  deny from all
  satisfy all
</files>

# Deny access to version file
<files inc/version.php>
  order allow,deny
  deny from all
  satisfy all
</files>

# Deny access to security file
<files inc/security.php>
  order allow,deny
  deny from all
  satisfy all
</files>
# END Security Features

1 个答案:

答案 0 :(得分:1)

只需将它们全部添加到您已有的规则之上:

RewriteEngine On

RewriteRule ^(about|page1|page2|etc)$ /index.php?page=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([_A-Z0-9a-z-+\.]+)/?$ ./pages/player.php?p=$1 [L]
RewriteRule ^id/([_0-9-+\.]+)/?$ ./pages/player.php?id=$1 [L]

假设您拥有的页面列表是&#34;关于&#34;,&#34; page1&#34;,&#34; page2&#34;,&#34; etc&#34;。请注意,执行此类操作意味着您的播放器名称与您的页面名称相同。