Solve problem with URL rewrite with .htaccess

Question

I am writing a web application in PHP. I’m trying to rewrite urls with this pattern:

www.mydomain.com/buy/next/

from the pattern:

www.mydomain.com/index.php?url=buy/next/

I am using here the PHP $_GET method and calling with the var $_GET[‘url’]. And It is working great on almost any cases.

But when I’m trying to use a string value rather than variable the problem arises. The problem happening with the trailing slash at the end of the url. This problem also happening for folder. For example “blog“. It can be a folder or string. In this case when I use this $_GET method the url exposes without trailing slash something like this:

www.mydomain.com/blog/ - OK, the url stays just like that and its fine.

But in the String and folder cases its exposes like this:
www.mydomain.com/blog - Heres the problem, this url ultimately redirects browser to:

www.mydomain.com/admin/?url=blog

So. like variable, I want to expose the url without  “url=blog” pattern.

So how can I do this? Here is my .htaccess file:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} -d RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
Solve problem with URL rewrite with .htaccess
4.7 (93.33%) 6 votes

0
Steve-baker 6 months 0 Answers 93 views Novice 0

Leave an answer

About Steve-bakerNovice