Question

How can I rewrite if $1 is nothing to 'index'?

Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{REQUEST_URI}  !/assets
RewriteRule (.*)  index.php?p=$1 [QSA]

</IfModule>

Example:

If I go to mysite.com/test the output is

Array ( [p] => test )

And when I go to mysite.com the output is:

Array ( [p] => )

So, how can I rewrite $1 to 'index' when I go to mysite.com? Like this:

mysite.com:

Array ( [p] => index )

Was it helpful?

Solution

Use this code:

RewriteEngine On

RewriteCond %{REQUEST_URI} !/(assets|index\.php) [NC]
RewriteRule ^/?$ index.php?p=index [L,QSA]

RewriteCond %{REQUEST_URI} !/(assets|index\.php) [NC]
RewriteRule ^(.+)$ index.php?p=$1 [L,QSA]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top