eZ Community » Forums » Developer » How to shorten url via RewriteRule ?
expandshrink

How to shorten url via RewriteRule ?

How to shorten url via RewriteRule ?

Tuesday 07 August 2012 2:43:38 pm - 2 replies

Hi,

I need to promote short urls of my website on social networks.
To create those short urls, I thought I could just use an Apache RewriteRule and node_id.

Example :

Short : http://www.jobmarks.fr/s/8784 (/s/ standing for "short"...)

Long : http://www.jobmarks.fr/content/view/full/8784

Unfortunately, I can not have the redirect to work when I had this rule in Apache : 

Rewriterule ^/s/(.*) /content/view/full/$1
=> I get a blank page with error message "The requested URL /p/8783 was not found on this server."

Rewriterule http://www.jobmarks.fr/s/(.*) http://www.jobmarks.fr/content/view/full/$1 [L]
=> I get an ez page with error message "The requested module s could not be found."

What do you think ?

Could I make it with RewriteRules ?

Do you think I have to use an extension such as http://share.ez.no/blogs/maxime-thomas/a-new-extension-is-out-for-ezpublish-wascou-software-edition-url-shortener/(language)/eng-GB ?

Thanks in advance for your help happy.gif Emoticon

Mickael

Wednesday 08 August 2012 8:42:41 am

Hi Mickael,

A few points:

  1. Your RewriteRules have a lowercase "r" on the Rule - this will cause Apache to fail
  2. Your 1st RewriteRule looks ok, but should probably have an [L] at the end
  3. Are you using .htaccess or VirtualHosts?  If .htaccess, you need to remove the beginning slash, ie ^s/ 
  4. You can forget RewriteRules completely and just use the built-in eZ Publish functionality in Admin > Setup > URL wildcards
    e.g New URL Wildcard = s/* and Destination = content/view/full/{1}

Hope that helps!  If it resolves your issue, please click the speech bubble up top to mark this issue as resolved.

Cheers,

Geoff

Modified on Wednesday 08 August 2012 8:43:48 am by Geoff Bentley

Wednesday 08 August 2012 10:51:34 am

Hi Geoff,

Thanks a lot for your precise and useful answer.

Url wildcards indeed seem to fulfill my need, and are very simple to set !

Thanks again happy.gif Emoticon

Mickael

Modified on Wednesday 08 August 2012 10:52:03 am by Mickael Robin

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from