0

I currently have a website with URLs with this pattern

https://website.com/?p=something

where p is the requested page (like /?p=login)

for SEO reasons i want the URL to look like this

https://website.com/login/

Of course I could do a redirect like this

Redirect 301 /login/ https://website.com/?p=login

But it would change the URL displayed in the users browser back to the URL with parameters in it.

My question is, how can I have an URL like this https://website.com/login/ but in PHP inside the index.php I could access the requestet page or "path" like before like $page = $_GET['p'];. In other words I want to redirect the URL https://website.com/login/ to https://website.com/?p=login but having the URL still displayed as https://website.com/login/.

1 Answer 1

1

I'd suggest to use .htaccess file to point all requests to the server to one file for example index.php

# Rewrite Engine ON
RewriteEngine on

# Redirect everything to one file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

After that you can code a router to handle URI components.

For example someone call sitename/login

You detect /login and open the required page

Sign up to request clarification or add additional context in comments.

3 Comments

is it possible to make an exception to that rule? eg. for /sidemap.xml ?
I tried to add the following condition RewriteCond %{REQUEST_URI} !^sitemap.xml but it's still being redirected...
This above is working only for paths without extensions, so no need to change it sitename/sitemap.xml will work aswell as sitemap/script.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.