Php 如何使用.htaccess设置备用url

Php 如何使用.htaccess设置备用url,php,.htaccess,socialengine,Php,.htaccess,Socialengine,我有一个网站urlwww.test.com/profile/david 现在我需要输入urlwww.test.com/david 如何通过.htaccess实现 我现有的.htaccess文件如下 <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On # Get rid of index.php RewriteCond %{REQUEST_URI} /index\.php Rewrit

我有一个网站url
www.test.com/profile/david

现在我需要输入url
www.test.com/david

如何通过.htaccess实现

我现有的.htaccess文件如下

<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]


</IfModule>

# sends requests /index.php/path/to/module/ to "index.php"
# AcceptPathInfo On

php_value upload_max_filesize 7M
php_value post_max_size 20M

# @todo This may not be effective in some cases
FileETag Size

选项+FollowSymLinks
重新启动发动机
#去掉index.php
重写cond%{REQUEST_URI}/index\.php
RewriteRule(.*)index.php?rewrite=2[L,QSA]
#重写所有查找目录的URL
重写cond%{REQUEST_URI}/$
RewriteRule(.*)index.php?rewrite=1[L,QSA]
#尝试路由丢失的文件
重写cond%{REQUEST_FILENAME}-F
RewriteCond%{REQUEST_FILENAME}public\/[或]
重写cond%{REQUEST|u FILENAME}\(jpg | gif | png | ico | flv | htm | html | php | css | js)$
重写规则[L]
#如果文件不存在,请重写为索引
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?重写=1[L,QSA]
#将请求/index.php/path/to/module/发送到“index.php”
#上的AcceptPathInfo
php\u值上传\u最大\u文件大小7M
php_值后最大尺寸20M
#@todo这在某些情况下可能无效
文件标签大小
您可以使用此规则:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\w+)/?$ /profile/$1 [L]

,感谢您的回复。但它不起作用。更改.htaccess文件后是否需要重新启动apache?@anubhava。请再次查看问题。我添加了现有的.htaccess文件,很抱歉这么说,但这些是我见过的最奇怪的规则,我可以看到很多规则都不起作用。我需要知道你那边的CMS/PHP框架是否提供了
/profile/david