-1

I ned to change this url

https://halopredictions.com/blog/index.php?url=german-bundesliga-prepare-to-return-on-9-may

to

https://halopredictions.com/blog/german-bundesliga-prepare-to-return-on-9-may

This is my .htaccess that am currently using

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

I have already enabled mod rewrite The htaccess is on this path ...\blog\.htaccess

Any help I will highly appreciate

asega
  • 33
  • 8
  • Your Htaccess Does Almost The Opposite of What You Asked to. It Converts `https://halopredictions.com/blog/german-bundesliga-prepare-to-return-on-9-may` to `https://halopredictions.com/index.php?url=blog/german-bundesliga-prepare-to-return-on-9-may` – Harish ST Apr 24 '20 at 04:41
  • https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained This Will Help You! – Harish ST Apr 24 '20 at 04:57

1 Answers1

0

Before proceeding with the answer, if I understand correctly you want to redirect from https://halopredictions.com/blog/german-bundesliga-prepare-to-return-on-9-may To https://halopredictions.com/blog/index.php?url=german-bundesliga-prepare-to-return-on-9-may.

Since SEO Urls are used by the visitors, we have to convert them to actual path. The below RewriteRule will be sufficient to achieve the above condition.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^blog/([A-Za-z0-9-\+]+)/?$ blog/index.php?url=$1 [NC,L,QSA]

Explanation:

^blog/([A-Za-z0-9-\+]+)/?$ - This part is what you want to rewrite from. Since, your URLs will be like in the pattern https://halopredictions.com/blog/german-bundesliga-prepare-to-return-on-9-may, we need to get the url part after blog/. I have used a regular expression ([A-Za-z0-9-\+]+)/? to match the url part and it can be referrenced using $1.

Now we have to use $1 in our new url. For that, we have written the second part of RewriteRule where you can assign the referrence. blog/index.php?url=$1 - Now, as you would assume we are using the $1 reference after index.php?url=, so that it will append it to the URL Query param and should lead to a valid path.

By the way, ^ this is used to indicate the start and $ for the end.

Harish ST
  • 1,475
  • 9
  • 23
  • Can you further explain what you are trying to achieve ? – Harish ST Apr 24 '20 at 18:39
  • I am using GET method to get the content from the DB `https://halopredictions.com/blog/index.php?url=german-bundesliga-prepare-to-return-on-9-may`. As you can see am **Selecting from the db where url = german-bundesliga-prepare-to-return-on-9-may.** But I don't want viewers to see it that way, instead to see it this way `https://halopredictions.com/blog/german-bundesliga-prepare-to-return-on-9-may` – asega Apr 25 '20 at 02:29
  • Are you using any framework? URL and DB don't have any relation between them. When you perform a GET request, the language PHP is making the Query to the Database and Showing the Data to the User. The URL is not anyway related with the Database. – Harish ST Apr 25 '20 at 12:57
  • Thank you. Now what is your recommendation on this so that I can achieve that. Maybe another way to do it – asega Apr 27 '20 at 09:25
  • Can you mention the Folder Structure? – Harish ST Apr 27 '20 at 09:54
  • `html > blog > index.php` – asega Apr 27 '20 at 10:48
  • If `html` is your project folder then put `index.php` in the web-root. That is, `html > index.php`. Then you can create a blog post inside the `blog` directory. ie; `html > blog > blog-post.php`. So when you redirect from `index.php` to Blog post, you will get the desired URL. But I think you should create some Routing Service, if you want to go forward with this. Alternatively, you can use Free Libraries or Frameworks in PHP to solve the issue. I am still not sure why you need to `reinvent` the wheel! – Harish ST Apr 27 '20 at 12:15
  • I got you. Thanks – asega Apr 27 '20 at 14:00