skip to Main Content

I have the file path: example.com/blog/ where blog is a directory. Blog gets a query string from the URL called URL and makes a dynamic page out of that information. So essentially it’s something like this: example.com/blog?url=hello-world but i’d like to remove the ?url part and instead add a slash. So it should look something like this: example.com/blog/hello-world I’ve tried to accomplish this by putting the .htaccess file in the blog directory. This is my current .htaccess file, but it is not working:

.htaccess

RewriteEngine On
RewriteBase /stories/

RewriteCond %{THE_REQUEST} /?url=([^&s]+) [NC]
RewriteRule ^ %1? [L,R=302]

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

Inside /blog there is a index.php file and that generates the dynamic page.

2

Answers


  1. RewriteEngine On    # Turn on the rewriting engine
    RewriteRule    ^blog/([A-Za-z0-9-]+)/?$    blog/index.php?url=$1    [NC,L]
    RewriteRule    ^blog/?$    blog/index.php    [NC,L]
    
    Login or Signup to reply.
  2. Try this one.

    EDIT

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^(blog)/(.*)$ blog/index.php?url=$1 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search