0

I'm trying to add rewrite rule for url in .htaccess in IMPERSSPAGES CMS. I have example.com/obj?id=123 and I want it to look like example.com/obj/123 Is it even possible because there is already a rewire rule in htaccess pointing to index.php:

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [L]

2 Answers2

1

You have to add the Redirect flag at the end and a directory slash at the beginning for this to work. Otherwise the last rule will still be called and IP routing will throw a 404 error.

Before

RewriteRule ^obj/(\d+)/?$ your-script.php?id=$1 [L]

After:

RewriteRule ^obj/(\d+)/?$ /your-script.php?id=$1 [R,L]
John
  • 123
  • 1
  • 6
0

You can use:

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^obj/([0-9]+)/?$ obj?id=$1 [L]
RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [L]
Croises
  • 18,570
  • 4
  • 30
  • 47