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 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法