douyi1939
2017-03-24 10:21
浏览 106
已采纳

Mod Rewrite:如何重写URL将所有内容传递给index.php

I enabled mod_rewrite and checked it with phpinfo().

I placed a .htaccess file with

RewriteEngine on

RewriteRule ^(.*)$ index.php?/$1 [L]

and a index.php file at apache root directory (/var/www/html/).

Working URL:

http://192.168.56.101/index.php

http://192.168.56.101/index.php/edrgderg

Failing (404) URL:

http://192.168.56.101/sgghsshgfhfgj

Mod_rewrite should form this to http://192.168.56.101/index.php/sgghsshgfhfgj , but it doesn't.

I want to redirect each request to index.php.

SOLUTION:

I had to edit my apache configuration:

sudo nano /etc/apache2/sites-enabled/000-default.conf

I added:

<Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>

As sugested here: https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04

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

我启用了mod_rewrite并使用 phpinfo()进行了检查。

我在< > RewriteEngine上放置了一个带有

  RewriteEngine的.htaccess文件^(。*)$ index.php?/ $ 1 [L] 
 <  / code>  
 
 

和apache根目录下的index.php文件(/ var / www / html /)。

工作网址:

  http://192.168.56.101/index.php

http://192.168.56.101/  index.php / edrgderg 
   
 
 

失败(404)URL:

  http://192.168.56.101/  sgghsshgfhfgj 
   
 
 

Mod_rewrite应该将此形成为 http://192.168.56.101/index.php/sgghsshgfhfgj ,但事实并非如此。

我想将每个请求重定向到 index.php

解决方案: < / p>

我必须编辑我的apache配置:

  sudo nano /etc/apache2/sites-enabled/000-default.conf
    
 
 

我添加了:

 &lt; Directory / var / www / html&gt; 
选项索引FollowSymLinks MultiViews 
  AllowOverride All 
订单允许,拒绝
允许来自所有
&lt; /目录&gt; 
   
 
 

这里是sugested: https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04

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

1条回答 默认 最新

  • doulao5916 2017-03-24 10:28
    已采纳

    Exclude existing files/directories from your rewrite rule to avoid looping the rules:

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* index.php?/$0 [L,QSA]
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题