Mobile app version of vmapp.org
Login or Join
Murray432

: URL Rewrite - remove ?url I have an address which is /blog?url=article-1 Is there a way to just remove the ?url= part and replace it with a forward slash? So, in the end, the URL should

@Murray432

Posted in: #UrlRewriting

I have an address which is /blog?url=article-1

Is there a way to just remove the ?url= part and replace it with a forward slash?

So, in the end, the URL should look like /blog/article-1

I have tried many htaccess routes and none seem to work.

I am using Windows and I am building a simple blog.

The URL works and everything but I just need it to look like /blog/article-1 instead of /blog?url=article-1.

What I have mainly tried when searching on Stack Overflow is this code:

RewriteRule ^edit/id/([0-9]+)/?$ edit.php?id= [NC,QSA,L]


Changed the values in it with no luck, what would I change the above code to? Or is the above code entirely wrong for what I need?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Murray432

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

The URL works and everything but I just need it to look like /blog/article-1 instead of /blog?url=article-1


This should be done in your web application, not .htaccess. It is a common mistake (at least a common question) to attempt to do this part in .htaccess, as it will result in multiple external redirects on every request - which is not desirable.

The only time you do this in .htaccess is when you need to correct old URLs that have been indexed and linked to. Essentially a canonical redirect.


RewriteRule ^edit/id/([0-9]+)/?$ edit.php?id= [NC,QSA,L]


What you should then use .htaccess for is to internally rewrite the virtual (pretty) URL to the real URL. That is what this directive is doing.

So, the basic process is:


User clicks on "virtual" link (a URL) on your website: /blog/article-1
Directive in .htaccess internally rewrites the request to the real file that handles the request: /blog.php?url=article-1. (Although the file extension is missing on the URLs in your question.) Since this is an internal rewrite (as opposed to an external redirect) the URL in the address bar does not change.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme