【问题标题】:How to set alternate url using .htaccess如何使用 .htaccess 设置备用网址
【发布时间】:2014-03-05 04:57:39
【问题描述】:

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

现在我需要通过输入 url 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

【问题讨论】:

    标签: php .htaccess socialengine


    【解决方案1】:

    你可以使用这条规则:

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

    【讨论】:

    • ,感谢您的回复。但是它不起作用。我需要在更改 .htaccess 文件后重新启动 apache 吗?
    • @anubhava。请再次查看问题。我添加了现有的 .htaccess 文件
    • 很抱歉这么说,但这些是我见过的一些看起来最奇怪的规则,我可以看到其中大部分甚至不起作用。我需要知道/profile/david 是否由您身边的某个 CMS/PHP 框架提供服务?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 1970-01-01
    • 2014-10-14
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多