Wordpress blog page with $_GET
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

In my wordpress (3.4) blog, I have created a page called "mypage". Using my rewrite settings, it is shown in the address bar as http://www.domain.com/profile.

I am using a custom page template and am processing some things, which include the use of GET variables. For instance:

if (isset($_GET='n')) { echo $_GET['n']; }

So, http://www.domain.com/profile?n=username will display "username". The problem I am having is rewriting the URL so that it can look like: http://www.domain.com/profile/username, still being able to access "username" as the GET variable.

Does anyone know what I need to add to my .htaccess to achieve this?

What do you have in your .htaccess right now for the rewrite?
skram 4 years ago
awarded to Wikimedia

Crowdsource coding tasks.

4 Solutions

I think you should be able to resolve this by adding [QSA] to the end of your RewriteRule[1]

  1. http://stackoverflow.com/questions/4071155/keep-url-parameters-with-htaccess-rewrite
I need work code :|
hatasu 4 years ago
What have you got in your .htaccess so far for this?
skram 4 years ago

RewriteBase /
RewriteRule ^profile/(.*)$ /profile?n=$1
I got 404 error...
hatasu 4 years ago

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^profile/(.*)$ ./profile?n=$1 [QSA]
I write it before "# BEGIN WordPress" - but dont work.
hatasu 4 years ago

try this (full .htaccess code):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile/(.*)$ /profile?n=$1 [QSA]
RewriteRule . index.php [L]
# END WordPress
Images and css files is broken (404), and domain.com/profile/name too
hatasu 4 years ago
View Timeline