Mod_Rewrite rule help

gr1z
gr1z used Ask the Experts™
on
Greetings!

I'm trying to write a custom rule that I can't seem to figure out.

Example:

http://domain/sections/time/  ---> should go to http://domain.com/#/sections/time/

http://domain/sections/time/invoices  ---> should go to http://domain.com/#/sections/time/invoices

/sections/whatever/ ---> #/sections/whatever/

/sections/time/invoices/today/tomorrow/ --->  #/sections/time/invoices/tomorrow/

I don't know how deep the folders will get... basically just wanting to add a pound sign in front of anything that's in /sections/.

Please help!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
What we're trying to do is prevent a user from directly accessing these pages without the pound sign.

We're using some jquery stuff so that we have basically a single page to server hundreds of other pages.

The problem right now is a user could go to /sections/time/ and see the page directly... we want to prevent this by rewriting the url to have a pound sign.
Commented:
Your syntax is wrong:
Redirect 301 /old.html http://www.mysite.com/new.html

No domain reference on the source, but yes on the target.

See here for more:
http://www.squidoo.com/301

Author

Commented:
redirectMatch 301 ^domain\.net$/section/^.*$ /#/section/$1


This works... if I go to http://domain/sections/time it goes to http://domain/#/sections/time

BUT

If I go to http://domain/sections/time/calendar it doesn't redirect and I can access the file directly as if it's not working.
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Author

Commented:
And actually the part that does work... has a bug...


This works... if I go to http://domain/sections/time it goes to http://domain/#/sections/time

BUT if you do this... you can directly access it still

This works... if I go to http://domain//sections/time
David S.Consultant & Challenge Subduer
Top Expert 2009
Commented:
The problem is that when servers sees a # in your URL, it removes the special character and interpretes the URL without pound sign.
The matter is that pound sign is used by browsers to name anchors within a document and it must not pass it to the server. For example if you enter http://www.domain.com/dictionary#someword in your browser, it sends a request for /dictionary to the server, downloads the whole document and then scrolls down to anchor named someword.
If browser passes the pound sign to the server, it will assume that some mistake has taken place and ignores the pound sign.
Try using some other special character in your jquery stuff.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial