Jump to content

Redirect Id Based Urls


adrian
 Share

Recommended Posts

Sorry @Nukro - I haven't tested with multisite. Perhaps if you can point me to where the problem is I can figure out a fix. Unfortunately I don't have time at the moment to setup the multisite module to test myself.

Let me know if you can narrow it down.

Link to comment
Share on other sites

16 hours ago, adrian said:

Sorry @Nukro - I haven't tested with multisite. Perhaps if you can point me to where the problem is I can figure out a fix. Unfortunately I don't have time at the moment to setup the multisite module to test myself.

Let me know if you can narrow it down.

Hi @adrian

False Alarm.. I tested it again and it looks like it's working :lol:. Since the template/pages were protected, I had to loggedin in the right "domain root/alias".

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Hi @adrian

I have an question about urlSegments and your Module.

Let's say I have a url like this:

http://example.com/de/clinicroot.com/our-doctors/franz-muster/

I can access this site/url (http://example.com/de/clinicroot.com/our-doctors/) with the ID thanks to your module:

for example like this:

http://example.com/de/3412/ -> would redirect to -> http://example.com/de/clinicroot.com/our-doctors/

But how can I make it happen, that it would redirect to the url with the urlSegment? Is this somehow possible with your module? Or do I need to do some htaccess magic or something?

PS: At the moment my template code looks after the urlSegment, takes it and search it after the pagename(since franz-muster is the name of the page) in the db.

 

Greetings Nukro

Link to comment
Share on other sites

@Nukro - what you are after is certainly possible, but I am not sure the best way to make it handle everyone's need and not break current functionality for existing users because at the moment the module doesn't consider anything other than the page ID being somewhere in the URL. This allow ultimate flexibility in the URL, but obviously prevents detection of URL segments. I guess it could be a module config option to consider everything after the ID as segments that should be parsed.

Anyway, for now I have attached a version that should do what you want. Please test thoroughly and let me know how it goes. If it's working fine at your end, I'll probably make the urlSegment detection optional and release it.

ProcessRedirectIds.module

  • Like 2
Link to comment
Share on other sites

On 27.1.2017 at 10:15 PM, adrian said:

@Nukro - what you are after is certainly possible, but I am not sure the best way to make it handle everyone's need and not break current functionality for existing users because at the moment the module doesn't consider anything other than the page ID being somewhere in the URL. This allow ultimate flexibility in the URL, but obviously prevents detection of URL segments. I guess it could be a module config option to consider everything after the ID as segments that should be parsed.

Anyway, for now I have attached a version that should do what you want. Please test thoroughly and let me know how it goes. If it's working fine at your end, I'll probably make the urlSegment detection optional and release it.

ProcessRedirectIds.module

Thanks @adrian!

I will test the new version when we have finished the going live process of the website we are building. I had solved this problem last friday for the moment like this:

I activated urlSegments for the domain_root Template with this regex:

regex:^[1-999999]

Code at the beginning of the domain_root Templatefile:

if($input->urlSegment1){
	$id = $sanitizer->selectorValue($input->urlSegment1);
	$ziel = $pages->get("id=$id");
	if($ziel->id){
		if($ziel->is("template=news")){
			if($ziel->parent->id == 34044){
				$url = $overviews["news"].$ziel->name;
			}elseif($ziel->parent->id == 41821){
				$url = $overviews["media"].$ziel->name;
			}
		}
		$idMapping = array(
			"doctors" => $overviews["doctors"].$ziel->name,
			"specialties" => $overviews["specialties"].$ziel->name,
			"jobs" => $overviews["jobs"].$ziel->name,
			"signup-form-formbuilder" => $overviews["events"].$ziel->name,
			"baby" => $overview["baby"].$ziel->name,
			"news" => $url,
		);
		$session->redirect($idMapping[$ziel->template->name]);
	}
}

At the moment this quite works good for my needs.

 

Link to comment
Share on other sites

Hi @adrian

I have some Problem with the shortLinks. Your Module creates a Tab 'ShortLinks' for all pages with 3 links. The first one with only the id and the second one doesn't work anymore for me after I had installed an activated Multisite. But somehow the third one works. It looks like when the Link is starting with a id it redirects always to a blank page but all the other example links are working somehow.

 

Greetings

Orkun

Link to comment
Share on other sites

Yeah, I am not surprised those links don't work in the version of the module I posted for you - it is looking for url segments that don't exist. This is why I need to make looking for segments optional. As for the actual Shortlinks tab - I think it's probably time I got rid of that - I don't really think it serves a purpose - any thoughts?

Link to comment
Share on other sites

On 1.2.2017 at 3:35 PM, adrian said:

Yeah, I am not surprised those links don't work in the version of the module I posted for you - it is looking for url segments that don't exist. This is why I need to make looking for segments optional. As for the actual Shortlinks tab - I think it's probably time I got rid of that - I don't really think it serves a purpose - any thoughts?

Hi @adrian

What can I do for the moment, that it works again with only the id? Are you planning to release an update soon? 

In terms of the shortlink tab I think it doesn't really serves for a purpose.

Greetings Orkun

Link to comment
Share on other sites

8 hours ago, Nukro said:

What can I do for the moment, that it works again with only the id?

Can't you go back to the official released version?

Honestly I don't plan on spending too much time on this module - I don't think it gets much use. I created that new version for you to support url segments, but now it seems that you don't want them? Maybe I don't fully understand your needs. If you could give me a full explanation of all the scenarios you want supported I can take another go at it.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

just wanted to mention that this works fantastically for multilingual sites, thanks @adrian

yoursite.com/en/pageID

yoursite.com/fr/pageID

yoursite.com/de/pageID

:)

 

I also modified the module slightly so that the "shortlinks" only display for superuser

in the module file

	public function ready() {

		// we're interested in page editor only
		if(wire('page')->process != 'ProcessPageEdit') return;

		// skip changing templates (only target the actual edit form)
		$id = (int)$this->input->get->id;
		if(!$id) return;

		// wire('page') would be the page with ProcessPageEdit
		// GET parameter id tells the page that's being edited
		$this->editedPage = wire('pages')->get($id);

		// don't even consider system templates
		if($this->editedPage->template->flags & Template::flagSystem) return;
		// Display only for superuser so get current user and check if user is superuser
		$user = wire('users')->getCurrentUser();
        if($this->isAllowed($this->editedPage) && $this->editedPage->id != 1 && $user->isSuperuser()){
			$this->addHookAfter('ProcessPageEdit::buildForm', $this, 'addShortURLLinks');
		}
	}

 

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

I have an external php script (launched by cron) that uses ProcessWire (i.e. by including index.php, as explained here).

I have the ProcessRedirectIds module installed, and when I run the script I get this warning:

Notice: Undefined index: REQUEST_URI in /var/www/www.mysite.example/site/assets/cache/FileCompiler/site/modules/ProcessRedirectIds/ProcessRedirectIds.module on line 66

Obviously there is no REQUEST_URI in this case, but the module seems not aware of this possibility...

 

  • Like 1
Link to comment
Share on other sites

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...