0

我对 mod_rewrite 有疑问。

我有这样的链接

http://pagename.com/pl/meskie/longsleevy/criminal-squad#ad-image-0

我想在 # 之后“剪切”所有内容以获得

http://pagename.com/pl/meskie/longsleevy/criminal-squad

我的商店里有很多产品,所以我不想为每个产品创建很多规则。所以我创造了这样的东西:

RewriteRule ^/pl/meskie/longsleevy/([[^#]+)#([^#]+)$ ^/pl/meskie/longsleevy/([[^#]+)$

但这不起作用。有人可以帮助我吗?

我的实际 .htaccess

<IfModule mod_rewrite.c>

SetEnv HTTP_MOD_REWRITE On

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/media/
RewriteCond %{REQUEST_URI} !^/extAdmin/
RewriteCond %{REQUEST_URI} !^/skin/
RewriteCond %{REQUEST_URI} !^/js/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* index.php

</IfModule>

谢谢你,

4

1 回答 1

0

What about

RewriteRule ^/pl/meskie/longsleevy/([ˆ#]*)#.*$ /pl/meskie/longsleevy/$1

The brackets () on the left site will store everything before #, then print it with $1 on the right side. Also ^ and $ are useless on the right side.

Also, take care about the greedy .*

If you will change your mind and you want to rewrite url with fragment #, don't forget to add [NE] flag. See https://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_ne

Further reading apache docs

于 2013-08-23T06:18:36.930 回答