Reputation: 331
I'am quite new with htaccess. I have successfully created .htaccess file with following rules to redirect user with pretty url.
My actual url
http://localhost/domain.com/Job-Details.php?Job_ID=30
What i want to achieve
http://localhost/domain.com/30
My Current htaccess
RewriteEngine On
RewriteBase /domain.com/
# Get the URI-path directly from THE_REQUEST variable
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\s/(.*)\.php [NC]
# Search friendly URLs for job detail page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ Job-Details.php?Job_ID=$1 [NC,L,R=301]
Issues I'am facing
any idea what wrong i'am doing here.
Upvotes: 2
Views: 635
Reputation: 9007
Please try with the following /domain.com/.htaccess
code:
RewriteEngine On
RewriteBase /domain.com/
# Redirect actual URI to SEF URI
RewriteCond %{THE_REQUEST} (?:GET|HEAD)\s\/domain.com\/Job\-Details\.php\?Job_ID\=(\d+) [NC]
RewriteRule ^ %1? [R=302,L,NE]
# SEF URI for Job-Details page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\d+)$ Job-Details.php?Job_ID=$1 [NC,QSA,L]
Change R=302
to R=301
if you are happy with the results. Remember to clear your cache before testing this, otherwise your browser may redirect based on historical cache.
Upvotes: 2
Reputation: 597
Change this:
RewriteRule ^([0-9]+)$ Job-Details.php?Job_ID=$1 [NC,L,R=301]
RewriteRule ^([0-9]+)$ Job-Details.php?Job_ID=$1 [L,QSA]
With R=301 you were creating a 301 redirection.
Upvotes: 0