Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT2</strong></p> <p>Ok, now I think understand your question.</p> <p>You have url at play.php that used to handle all your urls and you want them to be redirected to the homepage.</p> <p>Here are two possible solutions. This is the first:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^/play.php* [NC] RewriteRule . /? [L,R=301] &lt;/IfModule&gt; </code></pre> <p>The above will redirect any requests to play.php to your home page using a 301 redirect, which means the redirect is permanent. This is different than a 302 redirect which is temporary. So it is important to redirect using 301.</p> <p>Also in this rewrite rule, we don't care if the url exists or not. So you don't need to have the actual play.php file or anything. It just matches based on the url.</p> <p>On the line for RewriteRule, there is a question mark at the end, this is to erase the query string from the url on redirect. I'm assuming you don't want the query string to carry over.</p> <p>The <code>[NC]</code> is for case insensitive matching, so <code>/PlAy.php</code> would be redirected also</p> <p>An alternative is use the Redirect directive:</p> <pre><code>Redirect 301 /play.php http://www.mysite.com/ </code></pre> <p>This will do a 301 permanent redirect to your homepage if the user tries go to play.php. The only downside of this is that the query string shows up. You can add a question mark at the end and it will erase the query string. Unfortunately the question mark stays.</p> <p>If you happen to have multiple endpoints and not just play.php, you can do the following:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^/play\.php* [NC, OR] RewriteCond %{REQUEST_URI} ^/another_url\.php* [NC] RewriteRule . /? [L,R=301] &lt;/IfModule&gt; </code></pre> <p>This RewriteRule will match play.php or another_url.php and do 301 redirect to your home page.</p> <p>Alternatively:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^/(play|another_url)\.php* [NC] RewriteRule . /? [L,R=301] &lt;/IfModule&gt; </code></pre> <p>Here is the alternative using the Redirect directive</p> <pre><code>Redirect 301 /play.php http://www.mysite.com/ Redirect 301 /another_url.php http://www.mysite.com/ </code></pre> <p>Alternative you could also use the RedirectMatch directive to use regex expressions (Note I haven't actually tested this one)</p> <pre><code>RedirectMatch 301 /(play|another_url)\.php http://www.mysite.com/ </code></pre> <p><strong>EDIT</strong></p> <p>Ignore this answer. I misread your question. The following redirects all requests to index.php unless the file or directory exists, which is not what you want now that I read your question.</p> <p>Here is how Wordpres does it. I believe Zend and Joomla also have variations of this.</p> <pre><code># BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt; # END WordPress </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload