0

Excellent help for my question is provided in this post. However, despite trying things as described therein I am still having problems because it seems as though my .htaccess file is not being parsed.

I have a website which consists of the following pages:

http://mywebsite.com/?menu1=home
http://mywebsite.com/?menu1=posts&menu2=johndoe
http://mywebsite.com/?menu1=posts&menu2=janedoe
http://mywebsite.com/?menu1=posts&menu2=nickdoe
http://mywebsite.com/?menu1=fashion&menu2=armani
http://mywebsite.com/?menu1=fashion&menu2=gucci
http://mywebsite.com/?menu1=about

The pages are displayed through the default index.php file in my xampp directory on Windows.

What would it take to have the browser respond to the following SEO frienly links instead? I would like to have my PHP code work with at least modifications as possible.

http://mywebsite.com/home
http://mywebsite.com/posts/johndoe
http://mywebsite.com/posts/janedoe
http://mywebsite.com/posts/nickdoe
http://mywebsite.com/fashion/armani
http://mywebsite.com/fashion/gucci
http://mywebsite.com/about

Thanks.

Community
  • 1
  • 1
John Sonderson
  • 3,238
  • 6
  • 31
  • 45

1 Answers1

1

You can use these rules in your Root/.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /?menu1=$1&menu2=$2 [QSA,NC,L]

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

The first rule rewrites "/posts/jondoe/" to "/?menu=posts&menu=jonde" and the second rule rewrites "/about" to "/?home=about"..

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • 1
    **RewriteCond %{REQUEST_FILENAME} !-d** tells apache to stop rewriting if the request is already for an existing directory (if you request a directory http://example.com/dir , then apache will not rewrite your request but it will serve you the directory you requested) – Amit Verma Sep 06 '15 at 18:23
  • 1
    **RewriteCond %{REQUEST_FILENAME} !-f** tells apache to stop rewriting if the request is already for an existing file (if you request an existing http://example.com/foo.php , then apache will not rewrite your request but it will serve you the file you requested) – Amit Verma Sep 06 '15 at 18:25
  • 1
    You can find more information about Url rewriting ,flags on Apache's official documentation http://httpd.apache.org/docs/current/mod/mod_rewrite.html – Amit Verma Sep 06 '15 at 18:35
  • OK, now I get it, the paths specified on the right-hand-side of the rewrite rules are absolute paths, so everything will be relative to `http://mywebsite.com/`. If these paths need to be relative to the directory .htaccess is found in, then make the paths relative. – John Sonderson Sep 07 '15 at 11:13