thetrooper1234 Posted June 20, 2022 Share Posted June 20, 2022 Hello everyone. I am having an issue with creating a rewrite for blog posts. Here is my .htaccess file. It doesn't work as intended. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] RewriteRule ^views/blog/?$ page.php?slug=/blog/ [L] RewriteRule ^views/blog/(.*)/?([0-9]*) page.php?page_slug=/blog/$1/$2 [L] index.php file points to the index.php in the views folder. Here is my folder stucture:root folder > views > blog > page.php The structure I'm trying to create is the following for any blog posts to be:mydomain.com/blog/post-title Any help would be much appriciated. Quote Link to comment https://forums.phpfreaks.com/topic/314944-htaccess-url-rewrite-issue/ Share on other sites More sharing options...
requinix Posted June 21, 2022 Share Posted June 21, 2022 So /blog/post-title does not exist as a file, right? Quote Link to comment https://forums.phpfreaks.com/topic/314944-htaccess-url-rewrite-issue/#findComment-1597520 Share on other sites More sharing options...
thetrooper1234 Posted June 22, 2022 Author Share Posted June 22, 2022 12 hours ago, requinix said: So /blog/post-title does not exist as a file, right? That's right. It's a in the database in a field "page_slug" associated with the page. In this case it's called "post-title" Quote Link to comment https://forums.phpfreaks.com/topic/314944-htaccess-url-rewrite-issue/#findComment-1597537 Share on other sites More sharing options...
requinix Posted June 22, 2022 Share Posted June 22, 2022 What are the rules in that .htaccess going to do if a file doesn't exist? Quote Link to comment https://forums.phpfreaks.com/topic/314944-htaccess-url-rewrite-issue/#findComment-1597538 Share on other sites More sharing options...
thetrooper1234 Posted June 22, 2022 Author Share Posted June 22, 2022 56 minutes ago, requinix said: What are the rules in that .htaccess going to do if a file doesn't exist? The page is page.php I was under the impression that dynamic links retrieving from a database can have better urls created for SEO? I might be completely wrong? Quote Link to comment https://forums.phpfreaks.com/topic/314944-htaccess-url-rewrite-issue/#findComment-1597540 Share on other sites More sharing options...
requinix Posted June 22, 2022 Share Posted June 22, 2022 Doesn't quite answer my question. The very first rule you have RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] says that anything that does not exist should go to index.php. If you want other things to apply first, other things that also do not exist, then those rules need to go before it. Quote Link to comment https://forums.phpfreaks.com/topic/314944-htaccess-url-rewrite-issue/#findComment-1597556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.