skip to Main Content

I write htaccess code that make my url seo friendly

RewriteEngine on 
RewriteBase /
RewriteRule ^p/([^/]+)/([^/]+)$ page.php?id=$1&title=$2 [QSA]

the real page access format is page.php?id={id}&title={title}.

And with htaccess p/{id}/{title}

So want I want to stop access page.php with real format. is that possible ?

2

Answers


  1. You actually cannot prevent page.php from accessing it in real format. The code in your .htaccess file only rewrites the URL to be SEO friendly and it does not redirects or prevents it from accessing in real format.
    For example these two links will both work without any error on your server:

    <a href="page.php?id=1&title=asd">link1</a> // will redirect you to the original format
    <a href="/page/1/asd/">link2</a> // will redirect you to the SEO friendly format
    

    The only way to “prevent” accessing it from other users in real format is to change every link into SEO friendly (see link2) and belive in that the user does not know the original format!

    Login or Signup to reply.
  2. Try with below rule below your current rewrite rule,

    RewriteCond %{REQUEST_FILENAME} ^page.php
    RewriteCond %{QUERY_STRING} ^id=$1&title=$2
    RewriteRule ^ - [F]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search