douyouchou1085 2014-06-25 21:09
浏览 80
已采纳

RewriteRule:发生异常 - 删除一个参数

I'm sorry for this "bad" title, I'll try to explain it:

My .htaccess looks like this:

Options -MultiViews

RewriteEngine On

RewriteBase /mythbusters/tsp/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

# RewriteRule ^album/(.+)$ index.php?url=album/show/$1
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

The last line of this file is working perfectly. It allows to rewrite my URL from _ROOT_/index.php?url=album/index to _ROOT_/album/index (I'm using this to work with those parameters and to create beautiful URL's.

Although, there's one exception I want to make:

The out-commented line in my .htaccess file is one of my uncountable tries to rewrite a specific URL.

With the last line of my .htaccess file, the working URL looks like this:

_ROOT_/album/show/name_of_album which is the same as _ROOT_/index.php?url=album/show/name_of_album

Now, I want to remove the "show" part of this URL, I tried to to it with

# RewriteRule ^album/(.+)$ index.php?url=album/show/$1

But using this, every other path in my site changes which causes the CSS files fail loading (just pure HTML, no styles).

Are there some missing flags or even some wrong regex in this file?

Thanks for your help.

Chris

  • 写回答

1条回答 默认 最新

  • dty97501 2014-06-25 22:03
    关注

    Have it like this:

    Options -MultiViews
    RewriteEngine On
    RewriteBase /mythbusters/tsp/
    
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l
    RewriteRule ^ - [L]
    
    RewriteRule ^album/(.+)$ index.php?url=album/show/$1 [L,QSA]
    
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
    

    For css/js/image issue: use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /.

    You can also try adding this in your page's HTML header: <base href="/" />

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

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大