[英]Why can't I redirect index.php to domain?
新的.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]
舊的.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]
域是http://localhost/sample/
。 我已經嘗試了Google給我的許多東西,但是都沒有用。 每次我轉到localhost/sample/index.php
它都不會重定向到localhost/sample/
。 我還使用了Redirect 301 /index.php /
。
我試過了
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
但是它將我發送到http://localhost/xampp/splash.php
。
我對.htaccess還是陌生的,所以我真的不知道我在做什么錯。 我已經嘗試了對OP表示答案有效的問題的答案。
您可以使用:
# 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/
來確保重定向從當前目錄的相對路徑發生。
用這個:
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.