doutuan6158 2014-07-29 16:20
浏览 43
已采纳

.htaccess重写规则即使经过所有必要的更改也无法正常工作

working for rewrite rules for my website couples of days now but failed to do it successfully. googled a lot and also found some very important threads here in stackoverflow,specially this one. I have made all the changes which are mentioned in the web.Before i talk about the changes i made to my httpd.conf, i want share the directory structure of my wamp

root directory for my website is C:/wamp/www/dist. index.php and .htaccess files for my website are kept Within this dist folder and there are other sub-directories for other files for my website.

MY CHANGES ::

wamp --> Apache --> Apache modules --> rewrite_module checked it

       ----------------IN MY APACHE httpd.conf file----------------

 LoadModule rewrite_module modules/mod_rewrite.so //removed # sign from it

 <Directory />
      Options FollowSymLinks
      AllowOverride All
      Order allow,deny
      Allow from all
  </Directory>

  <Directory "c:/wamp/www/">
      Options Indexes FollowSymLinks
      AllowOverride all
      Order Allow,Deny
      Allow from all
  </Directory>

  <Directory "c:/wamp/www/dist/">
     Options Indexes FollowSymLinks MultiViews
     AllowOverride all
     Order allow,deny
     Allow from all
  </Directory>

and now i have created a .htaccess file in my C:/wamp/www/dist (index.php is also here)

so my .htaccess looks like

<IfModule mod_rewrite.c>
     Options +FollowSymLinks
     RewriteEngine On
     RewriteBase /dist/
     RewriteRule ^([^/]*)\.html$ /dist/?path=$1
</IfModule>

Result/Error :: It is not working url remains the same(ugly) as before.no changes in url.

Error Explained :: from my any pages which are in other sub-directories i send a request to my index.php which looks like http://localhost/dist/?path=home and after checking the value of path variable index.php includes necessary file.so I want to my url as http://localhost/dist/home.but as i said it is not working.my url still remains http://localhost/dist/?path=home after creating .htaccess file

Note 1 :: i checked phpinfo() the modules are loaded.

Note 2 :: I tried by removing <IfModule mod_rewrite.c> from .htaccess but it has no effect all are same again

  • 写回答

1条回答 默认 最新

  • dqk42179 2014-07-29 16:30
    关注

    Keep your /dist/.htaccess like this:

    DirectorySlash Off
    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteBase /dist/
    
    # Use %{THE_REQUEST} to make an external redirect from /dist/?path=home to /dist/home
    RewriteCond %{THE_REQUEST} \?path=([^\s&]+)\s [NC]
    RewriteRule ^ %1? [R=302,L,NE]
    
    ## internal rewrite from /dist/home to /dist/?path=home
    # not a file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/?$ ?path=$1 [L,QSA]
    
    • THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules. Example value of this variable is GET /index.php?id=123 HTTP/1.1
    • QSA (Query String Append) flag preserves existing query parameters while adding a new one.

    Reference: Apache mod_rewrite Introduction

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

报告相同问题?

悬赏问题

  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别