Mod rewrite Apache-无循环重写url

Mod rewrite Apache-无循环重写url,mod-rewrite,url-rewriting,apache2,Mod Rewrite,Url Rewriting,Apache2,好吧,我再说一遍标题中的话,我找不到一种方法来重写我所有的URL而不得到一个循环。 我尝试了很多选择,但我找不到一种避免重定向循环的方法: RewriteRule ^/(.+) http://example.com/example/index.php$1 [R,L]

好吧,我再说一遍标题中的话,我找不到一种方法来重写我所有的URL而不得到一个循环。 我尝试了很多选择,但我找不到一种避免重定向循环的方法:

RewriteRule ^/(.+)  http://example.com/example/index.php$1  [R,L]                                                                                                                         
RewriteRule ^/?(.*) /var/www/example/index.php$1 [R]                                                                                                                              
RewriteRule ^/(.*)$ %{DOCUMENT_ROOT}/example/index.php$1 [R]  
RewriteRule ^$ /example/ [L]
下面是我的apacheconf目录

<Directory /var/www/example>
  Options FollowSymLinks
  DirectoryIndex index.php
  Order allow,deny
  Allow from all
</Directory>
我明白为什么它会循环,尽管我也无法想象它会找到!做我想做的事的好规则

编辑

基本上,我将托管在OVH的example.fr重定向到IP虚拟机。这会和我的问题有关吗

干杯

这将把/example/之外的任何内容重定向到/example/index.php,最后添加原始路径

编辑: 因此,如果希望将所有内容重定向到/project_name/index.php,则需要将RewriteCond和RewriteRule行中的单词example与项目名称交换

附言: 这里需要RewriteCond行,以确保重写不会循环,因此在尝试此操作时url为/example/contact

这将把/example/之外的任何内容重定向到/example/index.php,最后添加原始路径

编辑: 因此,如果希望将所有内容重定向到/project_name/index.php,则需要将RewriteCond和RewriteRule行中的单词example与项目名称交换

附言:
此处的RewriteCond行用于确保重写不会循环,因此在您尝试此操作时,url保持为/example/contact。

此规则不应导致循环

RewriteRule ^/(.+)  http://example.com/example/index.php$1  [R,L]
这条规则根本没用

RewriteRule ^/?(.*) /var/www/example/index.php$1 [R]
对于此规则,应添加重写条件

RewriteCond %{REQUEST_URI} !^/example/
RewriteRule ^/(.*)$ %{DOCUMENT_ROOT}/example/index.php$1 [R]
这很好

RewriteRule ^$ /example/ [L]

此规则不应导致循环

RewriteRule ^/(.+)  http://example.com/example/index.php$1  [R,L]
这条规则根本没用

RewriteRule ^/?(.*) /var/www/example/index.php$1 [R]
对于此规则,应添加重写条件

RewriteCond %{REQUEST_URI} !^/example/
RewriteRule ^/(.*)$ %{DOCUMENT_ROOT}/example/index.php$1 [R]
这很好

RewriteRule ^$ /example/ [L]

有了这个,我仍然能得到它的工作原理!来自apache的页面。我已经重新启动了apache/etc/init.d/apache2 restart1。你把这个放哪儿了?2.AllowOverride指令的值是多少?在/etc/apache2/httpd.conf中。我没有从默认站点启用的文件conf中获得任何权限。我会让您知道它是如何运行的。还是谢谢你。我相信它是有效的!页面打开/如果我转到example.fr/example,那么我将访问主页。但是,当我想转到例如example.fr/example/contact时,我得到了404,它是保持在/example.fr/example/contact URI上,还是当你得到404时url会改变?另外,您希望example.fr/example/contact准确重定向到哪里?到/example/index.php/example.fr/example/contact或其他地方?有了这个,我仍然可以得到它的工作原理!来自apache的页面。我已经重新启动了apache/etc/init.d/apache2 restart1。你把这个放哪儿了?2.AllowOverride指令的值是多少?在/etc/apache2/httpd.conf中。我没有从默认站点启用的文件conf中获得任何权限。我会让您知道它是如何运行的。还是谢谢你。我相信它是有效的!页面打开/如果我转到example.fr/example,那么我将访问主页。但是,当我想转到例如example.fr/example/contact时,我得到了404,它是保持在/example.fr/example/contact URI上,还是当你得到404时url会改变?另外,您希望example.fr/example/contact准确重定向到哪里?到/example/index.php/example.fr/example/contact还是其他地方?