dreamice2013
2015-03-28 02:05
浏览 63
已采纳

.Htaccess RewriteRule将所有页面重定向到404页面未找到错误

I have a long url in the following format

      example.com/user.php?uname=foo&pass=bar

the problem with this url is that it is not at all memorable,

So I want to change it into a search engine friendly url

  example.com/foo/bar

I have tried this rule in my htaccess that is on the web root

 RewriteRule ^([a-zA-Z0-9]+)([a-zA-Z0-9]+)/?$mysite.com/user.php?uname=$1&pass=$2

but the problem is that its not working ,It redirects every page requests to 404 not found.

Any ideas?

图片转代码服务由CSDN问答提供 功能建议

我有一个长网址,格式如下

 示例 .com / user.php?uname = foo& pass = bar 
   
 
 

这个网址的问题在于它根本不会令人难忘, \ n

所以我想把它改成一个友好的搜索引擎网址

  example.com/foo/bar
  \  n 
 

我在网络根目录下的htaccess中试过这个规则

  RewriteRule ^([a-zA-Z0-9] +)([  a-zA-Z0-9] +)/?$ mysite.com/user.php?uname=$1&pass=$2
nn

但问题是 它不起作用,它将每个页面请求重定向到404找不到。

任何想法?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsiy62758 2015-03-28 04:43
    已采纳

    Try this:

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ /user.php?uname=$1&pass=$2 [QSA,L]
    

    The conditions make sure you don't rewrite any existing file/directories on the server.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题