apache 如何将所有请求修改重写到单个文件而不导致无限循环

fcy6dtqo  于 2023-02-24  发布在  Apache
关注(0)|答案(4)|浏览(140)

如何将所有请求发送到www.myurl.com/{ANYTHING}并发送到www.myurl.com/index.php
我发现我可以发送一切与:

RewriteRule .* index.php [R=Permanent,L]

这很好用,只是由于安装了cpanel/apache,我被重定向到了www.myurl.com/home/username/public_html。

RewriteBase /
RewriteRule .* index.php [R=Permanent,L]

但这又会导致无限循环。

kmynzznz

kmynzznz1#

试试看:

RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule .* /index.php [R=Permanent,L]
wpx232ag

wpx232ag2#

对于Apache,请使用mod_rewrite:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
9avjhtql

9avjhtql3#

.htaccess网站

RewriteEngine On
RewriteCond %{REQUEST_URI} !.*\.(png|jpg|css|js)$ [NC]
RewriteRule ^(.*)$ index.php?URL=$1 [NC,L,QSA]


/etc/apache 2/可用站点/站点配置文件

<Directory /var/www/html>
        RewriteEngine On
        RewriteCond %{REQUEST_URI} !.*\.(png|jpg|css|js)$ [NC]
        RewriteRule ^(.*)$ index.php?URL=$1 [NC,L,QSA]
</Directory>
vdzxcuhz

vdzxcuhz4#

这有效地将我发送到index.php,而不会导致循环。

RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteRule ^(.*)$ - [L]

RewriteRule ^(.*)$ /index.php?url=%{REQUEST_URI} [R=302,L,QSA]

相关问题