Jump to content

page name generation in combination with urlSegments?


jom
 Share

Recommended Posts

Hi everyone

Since this is my first post: thanks for this beautiful CMS/CMF und thanks for this high quality forum.

I'm struggling with following: A client imports a list of books from a csv file (using module ImportPagesCSV). The page name gets autogenerated by the core (it takes the value from the title field). If the title is very long, the page name gets truncated to 128 characters. This works fine, as long as I don't use urlSegments. Using them, PW returns a 404:

http://domain.tld/...long-title-hier-128-characters.../ : works
http://domain.tld/...long-title-hier-128-characters.../urlSegment1/urlSegment2/  : does not work

It works fine, when I shorten the page name manually to e.g. 100 characters. This is not a good practice, since the client imports the list every couple of weeks.

Is this a correct behaviour? Should I limit the page name via API to 100 characters? If yes, would I do this in the ImportPagesCSV-Module or better implement as a hook?

 

Thanks in advance for some light in the dark!

Oliver

Link to comment
Share on other sites

I've run some local tests, and I can't reproduce the problem. Can you make sure there isn't any external software (firewall/proxy, browser addons etc.)  interfering with the request, i.e. compare the request URI sent by the browser and the entries in the web server rewrite and access logs? The whole URI should be passed to index.php in the "it" GET parameter. If it is, I'd also take a look at third party modules as a possible culprit.

Link to comment
Share on other sites

Thanks for your input, BitPoet. I've tried with several computers and browsers on different locations. No difference.

The request URI matches to the logged URI. Not sure about the "it" parameter: I inserted 

echo wire('input')->get('it');

into index.php. No result. Did I get you wrong?

There weren't any third party modules present when the problem occured the first time (apart of  ImportPagesCS).

Where would you set the limit for the page name? Add a module to the page->save hook?

Link to comment
Share on other sites

What I meant was comparing regular web server logs. Assuming you're using apache, you can enable logging for mod_rewrite and see if requests to /some/path are correctly re-written to /index.php?it=/some/path. If you can't see anything wrong there, I'm at a loss too.

A good place to hook would probably be Pages::saveReady.

  • Like 2
Link to comment
Share on other sites

I'm on a shared hosting environment, not sure if I can get the mod_rewrite logs. I asked the hoster for it.

In the meantime I implemented a workaround. Since the urlSegments are not vital, I skip them, if a 404 is based on a too long page name. For this I wrote a function which hookes into pageNotFound:

public function init() { 
  $this->addHookBefore('ProcessPageView::pageNotFound', $this, 'displayItem');
}
        
public function displayItem($event){            
	// redirects to url without segments, if there is a long page name involved
            
	$pageWithLongTitle = '';            
	$file = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);            
	$urlParts = explode('/', $file);            
	$urlWithoutSegments='';
            
	foreach($urlParts as $urlPart){
		if($urlPart){
			$urlWithoutSegments .= $urlPart.'/';
			if (strlen($urlPart) > 110){
				$pageWithLongTitle = $urlPart;
				break;
			}
		}                
	}

	// if there is a long title in url and a page with this title exists, then redirect
	if($pageWithLongTitle && wire('pages')->get("title=$pageWithLongTitle")){
		wire('session')->redirect('/'.$urlWithoutSegments);
	}            
}

Thanks for the help!

Link to comment
Share on other sites

In the meantime I got the mod_rewrite error log. Indeed, there is an error regarding my topic:

[Wed Oct 05 18:42:00.073367 2016] [core:error] [pid 85277:tid 34669321216] (63)File name too long: [client 12.34.56.78:54004] AH00127: Cannot map GET [here follows the repeated path]

It seems the paths gets in a loop - it is about 10 times repeated in one string. Now I'm lost - where to go from here? By the way in the first repetition the path is including the urlSegments, the following repetitions are without.

Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...