0

我想让用户通过输入 url http://www.mysite.com/username来访问他们的页面

所以将http://www.mysite.com/username重定向到http://www.mysite.com/profile/username

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On



  # Get rid of index.php
  RewriteCond %{REQUEST_URI} /index\.php
  RewriteRule (.*) index.php?rewrite=2 [L,QSA]


  # Rewrite all directory-looking urls
  RewriteCond %{REQUEST_URI} /$
  RewriteRule (.*) index.php?rewrite=1 [L,QSA]



  # Try to route missing files
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} public\/ [OR]
  RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
  RewriteRule . - [L]



  # If the file doesn't exist, rewrite to index
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]



   RewriteRule ^([A-Za-z_-]+)$ /profile/$1 [R] 


</IfModule>

为什么这行不通?

4

2 回答 2

2

试着把你的规则放在其他规则之前。你可以这样开始。

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([A-Za-z_-]+)$ /profile/$1 [R]
于 2011-09-12T08:14:34.410 回答
2

请注意,您可能会遇到用户与您已有的模块同名的问题。例如,如果有人将自己命名为组(出于某种原因)并且您安装并启用了组插件。

于 2012-09-07T18:40:59.157 回答