Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

.htaccess rewrite rule help

Featured Replies

Hi all. I'm having a issue with rewriting a rule for my ht access where I have have a simple slug work for my website I'm building :(

Here is my url for a dynamic page I have:
dev.mysite.com/views/blog/page.php?page_slug=post-one

I'm trying to get it so I can add the URL in the address bar so this would work:
dev.mysite.com/blog/post-one

Here is the current .htaccess
 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Any heklp most apprciated.

This should work:

RewriteEngine on
RewriteRule ^/(.*)/(.*)$ /views/$1/page.php?page_slug=$2 [L,NC,QSA]

If you don't want any query string to be appended to the URL then you don't have to include the 'QSA'.

  • 4 months later...

Here's one possible way to rewrite the rule in your .htaccess file to achieve the desired URL structure:

RewriteEngine On
RewriteRule ^blog/([a-zA-Z0-9-]+)/?$ views/blog/page.php?page_slug=$1 [NC,QSA,L]

 

This rule will match any URL that starts with "blog/" followed by one or more characters (alphanumeric or a dash) and an optional trailing slash. The matched string will be passed as the value of the "page_slug" query parameter to the "views/blog/page.php" file. The "NC" flag stands for "No Case" makes the pattern matching case-insensitive. The "QSA" flag stands for "Query String Append" it will append any existing query parameters to the rewritten URL. The "L" flag stands for "Last" it tells Apache to stop processing any more rules if this one is a match.

Please note that this is only one possible solution and it may not work for your specific case. It's also important to make sure that the .htaccess file is located in the root directory of your website and that the Apache mod_rewrite module is enabled.

 
 

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.