How to “cut” address - mod_rewrite

I have question about mod_rewrite.

I have links like this

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

And I want to "cut" everything after # to get

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

I have many products in my shop so I don't want to create many rules for every product. So I created something like this:

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

But this is not working. Can somebody help me?

My actual .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>

Thank You,

Answers


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


Need Your Help

Custom webserver caching

http caching http-headers webserver embeddedwebserver

I'm working with a custom webserver on an embedded system and having some problems correctly setting my HTTP Headers for caching.

Azure .NET language packs

.net azure localization

Are some .NET language packs deployed on Azure, or are we limited to en-US?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.