Hi,
I am using opencart and I want to rewrite a url through htaccess. I have tried to rewrite the url but it redirects me to the "page not found" page.
I have tried to rewrite the url using the following pattern

RewriteRule product/detail/(.*)/$  /index.php?route=pro/det&photo_id=$1

Please help.
Thanks in advance.

Dani AI

Generated

Summary and quick diagnosis (for , building on 's tests)
Your product rule is being trumped by the site-wide OpenCart catch‑all and the way you wrote the substitution. Putting a fully qualified URL or a leading slash in a substitution from .htaccess can force Apache to treat the target as a filesystem/absolute path (which on WAMP often shows up as a D:/... path and yields a 403). Also, a general catch‑all will capture requests unless the specific rule is evaluated first. (httpd.apache.org)

What to change (practical, safe steps)

  • Put the specific product rule before the generic OpenCart rule so it matches first.
  • Use a relative substitution (no leading slash, no full http:// URL) for an internal rewrite. Reserve [R=301] only for testing or when you want the browser to change its address bar.
  • Protect the catch‑all with checks so real files and directories are not rewritten.

Example of the idea (place this block above the site catch‑all)

# product detail (specific rule first)
RewriteRule ^product/detail/([^/]+)/?$ index.php?route=pro/det&photo_id=$1 [L,QSA]

# then the generic OpenCart forwarding (keep after; only when no file/dir)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?_route_=$1 [L,QSA]

This uses an internal rewrite (no leading slash) and keeps query strings. The pattern and conditions mirror the recommended OpenCart approach. (docs.opencart.com)

Debugging and perms
If you still see 403s: check your Apache Directory and AllowOverride settings for the vhost/WAMP, then enable rewrite tracing to see what mod_rewrite is doing (for example, use a rewrite trace via LogLevel). Test first with an external redirect ([R,L]) to confirm the match, then switch back to an internal rewrite. (stackoverflow.com)

Notes
Double-check the actual OpenCart route name (as hinted); a wrong route= will 404 even when the rewrite itself works.

Recommended Answers

All 7 Replies

Also ... are you sure that the target URL is valid? It seems like it shouldn't have the / in pro/det?

Yes the link is valid but I have this condition that is applied for the rist of the system

RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

I think this is creating problem.Is there any way to write url for the link I have mentioned the way I want keeping this condition on as I want both conditions to work .Thanks

I have changed the [R=301,L] to [L,QSA] and it is giving me the error Forbidden

You don't have permission to access /D:/wamp/www/projec/index.php on this server. 403 Forbidden

Let's tackle one rule at a time. Does the rule I came up with work without applying the other rule?

Also, are you ultimately using the other rule before or after the product/detail rule?

No the rule you applied did not work

Just out of curiosity, does it work without the backslash in the rerouted URL?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.