简体   繁体   中英

Pretty url not redirecting, htaccess

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

  1. Redirection with pretty url not happening. I'am stil seeing old url
  2. Using mentioned htaccess when i enter pretty url in address bar directly then page displays fine but url gets changed to my current url automatically.

any idea what wrong i'am doing here.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM