Run
Run

Reputation: 57196

Mod_rewrite: redirect to hash urls?

I want to redirect common URLs to hash URLs, like this below,

http://localhost/mywebsite/estate/heritage/

to

http://localhost/mywebsite/#/estate/heritage/

I have this rewrite code in my .htaccess,

RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$  #/$1/$2/  [R,L,NE]

But the result I get is,

http://localhost/C:/wamp/www/mywebsite/#/estate/heritage/

It has this extra bit C:/wamp/www/ which I don't want.

How can I remove it or how not to print it in my rewrite code?

Upvotes: 1

Views: 162

Answers (2)

anubhava
anubhava

Reputation: 785196

You can place this rule in /mysaite/.htaccess:

RewriteEngine On

# set ENV variable BASE equal to current RewriteBase value dynamically
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]

RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ %{ENV:BASE}#/$1/$2/ [L,NC,NE,R=302]

Using RewriteBase is very important to fix your stated problem.

Upvotes: 1

Bjørne Malmanger
Bjørne Malmanger

Reputation: 1477

You need a complete new URL, like so:

RewriteRule ^/mywebsite/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$  /mywebsite/#/$1/$2/  [R,L,NE]

Upvotes: 1

Related Questions