Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder: Plugins & Add-ons:
mod_rewrite for instant website

 

 


Jeffncou
User

Feb 3, 2012, 1:47 AM

Post #1 of 8 (2019 views)
Shortcut
mod_rewrite for instant website Can't Post

Please could you help me with the code needed for the htaccess file to change domainname.co.uk/index.php?item-1
to domainname.co.uk/item-1

Also would it be possible to include the mod re_write and then remove the option from the general info panel on the admin page.

Thanks


Tom P
User


Feb 3, 2012, 11:44 AM

Post #2 of 8 (1982 views)
Shortcut
Re: [Jeffncou] mod_rewrite for instant website [In reply to] Can't Post

Hi Jeffncou,

This thread http://www.interactivetools.com/forum/gforum.cgi?post=91562;search_string=htaccess;#91562 covers use of htaccess and mod_rewrite to redirect browser requests with some examples that are essentially the same as you are asking for.

There are no plans to include an .htaccess editor feature in CMSB currently but we are looking at improving SEO friendly URL's generated by CMSB pages.

Hope this helps,

Tom


Jeffncou
User

Feb 3, 2012, 12:21 PM

Post #3 of 8 (1975 views)
Shortcut
Re: [Tom P] mod_rewrite for instant website [In reply to] Can't Post

Hi Tom

I found that link on the forum and tried to follow it but I experience the same issue as user 1980

Here is the code I am using, as suggested in your previous post

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/([a-z]+)-([0-9]+)$ http://demo.wemakemagazines.co.uk/index.php?$1-$2 [NC]

I doesn't seem to work for me. Is there something specific on the instant website plugin that would stop it from working?


Tom P
User


Feb 3, 2012, 12:51 PM

Post #4 of 8 (1973 views)
Shortcut
Re: [Jeffncou] mod_rewrite for instant website [In reply to] Can't Post

Hi Jeffncou,

It seems that the format of your links is "Menu-2a-44" (string of letter dash string of letters and numbers dash string of numbers).

The current rule you're using is "string of letters dash string of numbers" which would not detect the above.

The expression to match against would be "([a-z]+)-([a-z0-9]+)-([0-9]+)" (any number of letters dash any number of letters and digits dash any number of digits).

The rule would then be:


Code
RewriteRule ^/([a-z]+)-([a-z0-9]+)-([0-9]+)$ /index.php?$1-$2-$3 [NC]


The rule follows the logic that any request to "domain.com/LettersOnlyWithNoOtherCharacters-LettersAndDigitsAreOk1234567890-1234567890" would be sent to "domain.com/index.php?LettersOnlyWithNoOtherCharacters-LettersAndDigitsAreOk1234567890-1234567890" and ignores case (the NC in square brackets at the end of the rule).

Note that if you want to allow any number of any character followed by a dash followed by any number of digits you would need:


Code
RewriteRule ^/(.*)-([0-9]+)$ /index.php?$1-$2 [NC]


The .* essentially means any number of any allowed character. It should be noted that it's better practice to be more specific with your expressions to make sure you're only affecting the requests you really want to. A more specific rule would then be


Code
RewriteRule ^/([\w\-]+)-([0-9]+)$ /index.php?$1-$2


In the above rule, we use the qualifier 'w' (any word character, alphanumeric plus underscores) and then specify dashes (prefixed with a backslash to denote a literal dash) enclosed in square brackets (meaning any character that matches either qualifier) followed by the plus sign (any number of characters that match either qualifier). since 'w' covers all characters we don't need to specify 'No Case' [NC] at the end of the rule.

mod_rewrite and htaccess rules are powerful and sometimes risky, resulting in unexpected or unintentional behavior - always have a safe backup of htaccess in case something goes wrong!

Let me know if this helps,

Tom


Jeffncou
User

Feb 4, 2012, 3:00 AM

Post #5 of 8 (1953 views)
Shortcut
Re: [Tom P] mod_rewrite for instant website [In reply to] Can't Post

Hi Tom,

Thanks for your reply and very thorough explanation.

If I have understood you correctly while the links that include a string of letters dash string of letters and numbers dash string of numbers won't work, those that consist of string of letters dash string of numbers should work with:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/([a-z]+)-([0-9]+)$ http://demo.wemakemagazines.co.uk/index.php?$1-$2 [NC


Therefore demo.wemakemagazines.co.uk/index.php?menu-2a-44 would result in a 404 error

but the rule would detect demo.wemakemagazines.co.uk/index.php?gifts-49 and replace with the desired demo.wemakemagazines.co.uk/gifts-49

However instead I get:
The requested URL /gifts-49 was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Any ideas? I have got rewrites to work correctly on other sites but for some reason it is not working with the instant website addon. I wonder if it has something to do with the following code in the website_init.php that comes supplied with the instant website plugin:

// modify page links for useSeoUrls
if ($website_config['useSeoUrls']) {
foreach (array_keys($categoryRecords) as $index) {
$category = &$categoryRecords[$index];
$category['_link'] = preg_replace('/index.php\//', '', $category['_link']); // remove index.php filename
$category['_link'] = preg_replace('/\/$/', '', $category['_link']); // remove trailing slash on SEO links
}
}

I appreciate your time on this - if you would prefer to move this to a paid for support request I would be happy to do so


(This post was edited by Jeffncou on Feb 6, 2012, 3:05 AM)


Tom P
User


Feb 6, 2012, 11:57 AM

Post #6 of 8 (1901 views)
Shortcut
Re: [Jeffncou] mod_rewrite for instant website [In reply to] Can't Post

Hi Jeffncou,

As usual, I've been only so thorough - if you remove the '/' from the pattern, making the rule:

Code
RewriteRule ^([\w\-]+)-([0-9]+)$ /index.php?$1-$2 [NC]

It'll catch all variations that end with a dash followed by a number and redirect them to "index.php?{query}".

I will take this opportunity to advise everyone who reads this, as I always do, to check every character of every line. The most common error is the dreaded typo!

Tom


Jeffncou
User

Feb 7, 2012, 12:35 AM

Post #7 of 8 (1874 views)
Shortcut
Re: [Tom P] mod_rewrite for instant website [In reply to] Can't Post

Hi Tom

That alone didn't work but I found an additional error in my set up. In the section editor for website pages my detail page url in admin/section editors/viewer urls was /index.php when it should have been index.php

Everything now works correctly. Thanks, as always, for the excellent after sales support


Tom P
User


Feb 7, 2012, 9:44 AM

Post #8 of 8 (1805 views)
Shortcut
Re: [Jeffncou] mod_rewrite for instant website [In reply to] Can't Post

Hi Jeff,

No problem and thank you for letting us know how you got it working!

Tom