Title: htaccess rewrite
Last modified: August 20, 2016

---

# htaccess rewrite

 *  [Colin Murphy](https://wordpress.org/support/users/colin-murphy/)
 * (@colin-murphy)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/htaccess-rewrite-1/)
 * Im having trouble trying to rewrite a url in my htaccess
 * The url is [http://www.example.com/bodega/gallery/album/nightlife](http://www.example.com/bodega/gallery/album/nightlife)
 * and on the server side i would it like to read
    [http://www.example.com/bodega/gallery?album=nightlife](http://www.example.com/bodega/gallery?album=nightlife)
 * The problem is if i use the below code it works but adds the query string to 
   the url which i dont want it to do
 *     ```
       RewriteRule ^gallery/([^/]+)/([^/]+) http://www.example.com/bodega/gallery?album=$2 [L]
       ```
   
 * If i use this code without [http://www.example.com](http://www.example.com) it
   brings me to a 404
    `RewriteRule ^gallery/([^/]+)/([^/]+)$ /bodega/gallery?album
   =$2 [L]`
 * Here is the full htaccess file `
    # BEGIN WordPress <IfModule mod_rewrite.c> 
   RewriteEngine On RewriteRule ^gallery/([^/]+)/([^/]+) [http://www.example.com/bodega/gallery?album=$2](http://www.example.com/bodega/gallery?album=$2)[
   L] #RewriteRule ^gallery/([^/]+)/([^/]+)$ /bodega/gallery?album=$2 [L] RewriteRule
   ^login$ [http://example.com/bodega/wp-login.php](http://example.com/bodega/wp-login.php)[
   NC,L] RewriteRule ^admin$ [http://example.com/bodega/wp-admin/index.php](http://example.com/bodega/wp-admin/index.php)[
   NC,L] RewriteBase /bodega/ RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME}!-
   f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /bodega/index.php [L] </IfModule
   > # END WordPress `
 * Any help would be grateful

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [Colin Murphy](https://wordpress.org/support/users/colin-murphy/)
 * (@colin-murphy)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/htaccess-rewrite-1/#post-2252496)
 * Any help would be grateful as I am really stuck on this issue.
 *  [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * (@big-bagel)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/htaccess-rewrite-1/#post-2252497)
 * What do mean “it adds the query string”? Queries other than `?album=nightlife`?
   Why do want to use `/?album=nightlife` instead of `/album/nightlife`? You’re 
   essentially undoing a bit of your pretty permalinks which results in a less friendly
   url.
 *  Thread Starter [Colin Murphy](https://wordpress.org/support/users/colin-murphy/)
 * (@colin-murphy)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/htaccess-rewrite-1/#post-2252499)
 * Hi Big Bagel.
 * Sorry if i was not clear enough so when you go to the URL `/bodega/gallery/album/
   nightlife` it changes the URL to `/bodega/gallery?album=nightlife`
 * Yes i want to keep the pretty URL and also on the server side run the query
 *  [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * (@big-bagel)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/htaccess-rewrite-1/#post-2252504)
 * Ah…you’re trying to do an internal rewrite so you can use the nice url. Got it.
 * I would assume that it changes the shown url in your first example because the
   full address makes it think it’s an external redirect. Why don’t you make your
   second example `[R,L]` so that you can see what url it’s trying to rewrite to.
   Once you see the problem you can fix it and take out the `R`. I wouldn’t trust
   my skills with any regex, but yours looks ok to me.
 * Is this query something not related to WordPress? (Custom taxonomies and such
   should still be able to make use of the normal WordPress rewrite rules to look
   nice)
 *  Thread Starter [Colin Murphy](https://wordpress.org/support/users/colin-murphy/)
 * (@colin-murphy)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/htaccess-rewrite-1/#post-2252518)
 * I removed the first RewriteRuleand added [R,L] to the second RewriteRule.
 * It is working but still adding the query string to URL instead of the pretty 
   URL.
 * Its related to calling out NGG Galleries.
 *  [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * (@big-bagel)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/htaccess-rewrite-1/#post-2252521)
 * The NextGEN Gallery plugin doesn’t automatically use nice permalinks or have 
   a setting for it? I thought the author added that a while ago. Since this is 
   specifically for that plugin you might get some more informed answers by asking
   the plugin author directly or at least adding the relevant tag (nextgen-gallery)
   to this topic in order to make it show up on the NextGEN plugin page.
 * Adding the R was to see exactly what URL the server would use with your second
   rewrite rule (since you said it was causing a 404). If everything worked, then
   removing the R should do exactly the same but without changing the shown URL.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘htaccess rewrite’ is closed to new replies.

## Tags

 * [htaccess](https://wordpress.org/support/topic-tag/htaccess/)
 * [permalinks](https://wordpress.org/support/topic-tag/permalinks/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/htaccess-rewrite-1/#post-2252521)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
