• Hi,

    I need to be able to keep wordpress on main page but also to keep the full requested URL (only for some special url).

    Example:

    http://www.mydomain.com/contant

    would lead for wordpress to load main page like http://www.mydomain.com/ but it will keep the string parametr contact so I can move the user to the correct position on the main page via the JS.

    And it will do only for 4 specific string parameters, otherwise it should lead to the home page without the parametr.
    Is it possible in WP?

    I need this for SEO usage. I have functional JS script that add this parametr to URL, but when user hit reload button, WP correctly says hat this URL is not found. And I need to get passed this and get to the script the string parametr.

    Thank you for any advice.

Viewing 1 replies (of 1 total)
  • i use a little trick to load a Template file for non-existent pages.

    It’s very simple. Hook the init-action and check the Request:

    class Theme {
    	function __construct() {
    		add_action('init', array($this, 'load'));
    	}
    
    	public function load() {
    			$template = null;
    
    			switch(!empty($_SERVER['REQUEST_URI']) ? basename($_SERVER['REQUEST_URI']) : null) {
    				case 'logout':
    					$template = 'logout.php';
    				break;
    				case 'weather':
    					$template = 'user/weather.php';
    				break;
    				case 'area':
    					$template = 'user/area.php';
    				break;
    				case 'overview':
    					$template = 'user/overview.php';
    				break;
    				case 'contact':
    					$template = 'user/contact.php';
    				break;
    				case 'forms':
    					$template = 'user/forms.php';
    				break;
    				case 'general':
    					$template = 'user/general.php';
    				break;
    				case 'news':
    					$template = 'user/news.php';
    				break;
    				case 'settings':
    					$template = 'settings.php';
    				break;
    			}
    
    			if(!empty($template) && file_exists(sprintf('%s/templates/%s', $this->path, $template))) {
    				status_header(200);
    				load_template(sprintf('%s/templates/%s', $this->path, $template));
    				exit();
    			}
    		}
    }

Viewing 1 replies (of 1 total)
  • The topic ‘Redirect (or rewrite) to main page without 404 error’ is closed to new replies.