社交引擎 URL 重写

发布于 2024-10-17 00:45:57 字数 1160 浏览 2 评论 0原文

我想让用户通过输入网址 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>

为什么这不起作用?

I want to let users access their pages by typing the url http://www.mysite.com/username

So to redirect http://www.mysite.com/username TO 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>

Why wont this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一绘本一梦想 2024-10-24 00:45:57

尝试将您的规则放在其他规则之前。你可以这样开始。

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([A-Za-z_-]+)$ /profile/$1 [R]

Try putting your rule before the other rules. You can start this way.

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([A-Za-z_-]+)$ /profile/$1 [R]
删除→记忆 2024-10-24 00:45:57

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

Just note of caution that you might run into an issue of a user has the same name as module you already have. For instance if someone named themselves group (for some reason or another) and you have the groups plugin installed and enabled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文