Htaccess rewrite question

Hi guys,

maybe someone is able to help. I need to find a rewrite URL mapping.

The original URLs have been like

domain.com/blogpage/?post=this-is-a-post
domain.com/blogpage/?post=this-is-a-post&tag=tag1&category=cat2

This should then look like in future (and map to above URLs)

domain.com/blogpage/this-is-a-post
domain.com/blogpage/this-is-a-post?tag=tag1&category=cat2

I tried different htaccess rewrite combinations, and failed until now. Any ideas?

Thanks in advance
Jannis

Hi Jannis,

mmh. Try this one:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?post=$1 [L,QSA]

Don’t think that would work - he wants to take the post= part and add it to the url - not as part of the GET variables.

1 Like

Anyone has a decent tutorial? I mean, a deep one?

When I need .htaccess info I always start here https://www.askapache.com/htaccess/

1 Like

Good tutorial here but not sure if it covers what you need (i am hopeless with this stuff!).

3 Likes

Me too 😂

1 Like

Hi Jannis,

Did you try something like this?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^blogpage/.*$ /blogpage/index.html


This is based on the SEO friendly URL scheme, if you place a page title right after the store page path in the URL, so that it looks like a subdirectory: www.mysite.com/blogpage/this-is-a-post .

But this is just a page on your server, not a directory. So if the server will try to find something inside the ‘blogpage’ , it will fail and return 404 errors. To make your server properly process these URLs, you can configure URL rewrite rules as follows:

The general rule is to map everything after slash on a page to the blog page itself, i.e.: www.mysite.com/blogpage/anythingwww.mysite.com/blogpage

Specific configuration depends on your server:

I hope this helps some…

Cheers,

Ricardo

1 Like

Thanks all, I think I found a solution.

1 Like

Great,

Was it close to any of the suggestions? Do you mind sharing?

1 Like

At the end I was able to get it working with

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule blogpage/(.*) /blogpage/index.php?post=$1

But that’s not all, I also had to adjust my PHP code.

1 Like