SAQIBZAFAR
SAQIBZAFAR

Reputation: 89

RewriteRule not working with .htaccess

after doing some research i am still not sure that why this rewrite rule is not working on my server, i have checked on multiple hostings, but to no avail, the problem lies here:-

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

the last line above does not supply anything to GET on index.php, meaning $_GET is empty. Any suggestions?

PS: trying to implement this -> https://github.com/panique/php-mvc/blob/master/.htaccess

Upvotes: 1

Views: 167

Answers (2)

zx81
zx81

Reputation: 41838

Your rules look okay. Try a couple of tweaks:

Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)/?$ index.php?url=$1 [L,NE]

Upvotes: 1

S.Pols
S.Pols

Reputation: 3434

Try this:

Options +FollowSymlinks
RewriteEngine on

# check existing maps or files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]

# re-writing
RewriteRule (.*)$ index.php?url=$1

To get the URL you can use something like this in PHP:

$linkArray = explode("/",$_GET['url']);

You can stil access your GET parameters. If you use www.mywebsite.com/home/&message=hello it will rewrite it to www.mywebsite.com/?url=home/&message=hello. So with the explode you can get your URL parameters and for example with $_GET['message'] you can get the message.

Upvotes: 0

Related Questions