如何使用.htaccess设置备用URL

时间:2014-03-05 04:57:40

标签: php .htaccess socialengine

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

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

来访问同一页面

如何实现.htacccess?

我现有的.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

1 个答案:

答案 0 :(得分:1)

您可以使用此规则:

RewriteEngine On

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