简体   繁体   English

为什么不能将index.php重定向到域?

[英]Why can't I redirect index.php to domain?

New .htaccess file (still not working, it sends me to localhost/xampp 新的.htaccess文件(仍然无法正常工作,它将我发送到localhost/xampp

RewriteEngine on
RewriteBase /sample/

# set root to index.php
DirectoryIndex index.php 

# prevent directory listing
Options -Indexes

# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index.php$ $1 [R=301,L,NC] 

# removing extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)/?$ $1.php [L]

Old .htaccess file below: 旧的.htaccess文件如下:

RewriteEngine on

# set root to index.php
DirectoryIndex index.php 

# prevent directory listing
Options -Indexes

# removing extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# remove index.php
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://localhost/sample/ [R=301,L]

Domain is http://localhost/sample/ . 域是http://localhost/sample/ I have tried many things that Google has given me but none of them work. 我已经尝试了Google给我的许多东西,但是都没有用。 Every time I go to localhost/sample/index.php it doesn't redirect to localhost/sample/ . 每次我转到localhost/sample/index.php它都不会重定向到localhost/sample/ I also used the Redirect 301 /index.php / . 我还使用了Redirect 301 /index.php /

I tried 我试过了

RewriteCond %{THE_REQUEST} ^.*/index\.php 
RewriteRule ^(.*)index.php$ /$1 [R=301,L] 

But it sends me to http://localhost/xampp/splash.php . 但是它将我发送到http://localhost/xampp/splash.php

I am still new to .htaccess so I really don't have any idea what I am doing wrong. 我对.htaccess还是陌生的,所以我真的不知道我在做什么错。 I've tried the answers that have been given to the questions where the OP said the answer worked. 我已经尝试了对OP表示答案有效的问题的答案。

You can use: 您可以使用:

# set root to index.php
DirectoryIndex index.php 
# prevent directory listing
Options -Indexes
RewriteEngine on
RewriteBase /sample/

# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index.php$ $1 [R=301,L,NC] 

# removing extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)/?$ $1.php [L]

RewriteBase /sample/ is needed to make sure redirect happens from raltive path of current directory. RewriteBase /sample/来确保重定向从当前目录的相对路径发生。

Use this: 用这个:

RewriteEngine On

# prevent directory listing
Options -Indexes

# allows leaving off the extension (.php) in urls
Options +MultiViews

# removing extensions
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^index(\.php)?$ http://localhost/sample [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM