0
votes

I have problem using .htaccess to rewrite some of the friendly URL.

The root URL is http://www.example.com/my/

The working call url is http://www.example.com/my/Post.php?id=2

Both .htaccess file and Post.php are located in the sub-directory http://www.example.com/my/

But I wanted it to be like the following: http://www.example.com/my/job/kuantan/?id=2

The .htaccess configuration as below:

DirectoryIndex index.php

Options All -Indexes

#ErrorDocument 404 /404.php

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]

RewriteRule ^job/kuantan/([0-9]+)  /Post.php?id=$1 [L,QSA, NC]

BUT, once i deployed the above .htaccess configuration file, it prompted 500 internal error message as well.

Is something missing or wrong in the .htaccess configuration? Please advice and really appreciated if someone there could give a hand. Thanks.

3
Your rule is commented out, try removing # from #RewriteRule ^job/kuantan/([0-9]+) /Post.php?id=$1 [L,QSA, NC] - user169600
Hi IkoTiskashi , sorry i have removed the # comment. It didn't work either. Please advice! - Ray

3 Answers

0
votes

You should just need a single rule:

RewriteRule ^/my/job/kuantan/$ /my/Post.php

The query string is carried over by default.

0
votes

Assuming that .htaccess and Post.php are located in the sub-directory /my/:

DirectoryIndex index.php
Options All -Indexes
#ErrorDocument 404 /404.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^job/kuantan/([0-9]+)$  Post.php?id=$1 [L,QSA,NC]

Remove all spaces between []. Change /Post.php?id=1 to Post.php?id=$1.

0
votes

You can have this code in /my/.htaccess:

DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /my/

RewriteCond %{THE_REQUEST} /Post\.php [NC]
RewriteRule ^ job/kuantan [R=302,L,NE]

RewriteRule ^job/kuantan/?$ Post.php [L,NC]

Query String is automatically carried over so there is no need to capture it in rule.