douyan3478 2013-11-06 16:47
浏览 330
已采纳

.htaccess重定向到index.html,如果有参数,则重定向到index.php

I am looking for a .htaccess that does the following:

  1. For users that visit mydomain.com, the server should return the index.html file from the root.

  2. For users that visit mydomain.com/something/, mydomain.com/anything/123/, mydomain.com/some%20encoded%20text, etc., the server should return the index.php file from the root and pass the text after www.mydomain.com/ as a PHP $_GET variable.

I tried the WordPress .htaccess:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

But this redirects everything to the index.php file.

  • 写回答

1条回答 默认 最新

  • douzi5214 2013-11-06 16:49
    关注

    Enable mod_rewrite and .htaccess through httpd.conf (if not already enabled) and then put this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    
    RewriteRule ^$ /index.html [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+)$ /index.php?f=$1 [L,QSA]
    

    Inside index.php you can access $_GET['f'] variable that will give you requested URI.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题