.htaccess重写网址[帮助规则]

时间:2021-07-16 10:43:21

I'm trying to rewrite a url of this: http://www.foo.com/bar/baz

我正在尝试重写这个网址:http://www.foo.com/bar/baz

to

index.php?q=$1&d=baz

Where bar is not a fixed value, but baz is.

bar不是固定值,但baz是。

  RewriteRule ^(.*)\/baz$ index.php?q=$1&d=baz [L,QSA]
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

What i have above kinda works but unfortunately breaks all the includes in the site (css/javascript) but strangely all the pages work :/

我有上面的工作,但不幸的是打破了网站中的所有包括(css / javascript)但奇怪的是所有页面工作:/

This is a drupal install, (so the second line needs to remain).

这是一个drupal安装,(所以第二行需要保留)。

UPDATE

This might help actually, i forgot to include

这实际上可能有所帮助,我忘了包括

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  **RewriteRule ^(.*)/details index.php?q=$1&details=true [L,QSA]**
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

It seems to be doing my rewrite correctly, the only problem is it's ignoring the other conditional statements now, i.e. it's still attempting to rewrite files that exist (i.e. css,js) when it's mean to avoid them.

它似乎正在正确地进行重写,唯一的问题是它现在忽略其他条件语句,即它仍然试图重写存在的文件(即css,js),以避免它们。

site is fine without my line (The one with the stars), but with it, the variables and pages work, but static files like css etc are also being rewritten....need to stop that!

网站很好没有我的线(与星星一起),但有了它,变量和页面工作,但静态文件,如CSS等也正在被重写....需要停止!

Thanks in advance.

提前致谢。

Shadi

2 个解决方案

#1


Conditions only apply to the first rule immediately following. So try duplicating the condition lines.

条件仅适用于紧随其后的第一条规则。所以尝试复制条件行。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/details index.php?q=$1&details=true [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

#2


  RewriteRule ^(.*)/details index.php?q=$1&details=true [L,QSA]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

This is what finally worked. it just required the rearranging of the rules...

这是最终奏效的。它只需要重新安排规则......

#1


Conditions only apply to the first rule immediately following. So try duplicating the condition lines.

条件仅适用于紧随其后的第一条规则。所以尝试复制条件行。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/details index.php?q=$1&details=true [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

#2


  RewriteRule ^(.*)/details index.php?q=$1&details=true [L,QSA]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

This is what finally worked. it just required the rearranging of the rules...

这是最终奏效的。它只需要重新安排规则......