I have a website developed in PHP. I have recently done the URL rewriting which works fine. However, I just found out that my pages with parameters are also accessible. For eg.

I converted this URL
domainname.com/index.php?page=product&pid=5&proTitle=Samsung Galaxy

After rewrite it looks like this
domainname.com/products/5/Samsung-Galaxy.html

Everything works just fine. However, My site is still accessible using the old parameters. I want if someone types in the old URL should be automatically redirected to Ideally New Page if not then index page. Google and MSN shouldn't access these pages with parameter. Any help will be highly appreciated.

Dani AI

Generated

Short summary tied to the thread: the pretty URLs are already being rewritten to index.php (as showed) and was right that a 301 is the right direction — but it must be implemented so it only fires for direct requests to the old parameterized URL and not for the internal rewrite. The common causes of duplicate indexing are (a) the server serving both forms, and (b) redirects that create loops. The easy, safe fix is a server-side redirect that checks the original client request and then issues a single 301 to the canonical pretty URL.

Example .htaccess rules (place these before any internal rewrite rules):

RewriteEngine On

# Redirect direct client requests for index.php?page=product... to pretty URL
RewriteCond %{THE_REQUEST} \s/index\.php\?page=product&pid=([^&\s]+)&proTitle=([^&\s]+) [NC]
RewriteRule ^index\.php$ /products/%1/%2.html? [R=301,L]

Notes on that snippet: using %{THE_REQUEST} ensures only external requests trigger the redirect (prevents a loop when the server internally maps the pretty URL to index.php). Appending ? to the target clears the original query string so crawlers receive the clean URL.

If the goal is to remove parameterized URLs from search results (instead of redirecting), serve a 410 Gone for those requests:

# Serve 410 for legacy parameter URLs
RewriteCond %{QUERY_STRING} (^|&)page=product(&|$) [NC]
RewriteRule ^index\.php$ - [G,L]

SEO/operational tips: prefer 301 if preserving rankings; prefer 410 only if the old URLs must be purged. Ensure internal links and sitemap use the pretty URLs, add a rel="canonical" pointing at the pretty URL from the page output, and put the redirect rules before the internal rewrite. Test with curl (curl -I) to confirm headers and no redirect loops.

Recommended Answers

All 4 Replies

show the rewrite code that you are using, to allow people to make the alteration,
it is often just enough to include a 301 permanently moved to the redirect
but nobody will be able to make a correct assessment without seeing what exists

no answer after 5 days, so a simple hint, is add the url parameters to your rewrite code
can't give an eact description of the changes to make, as I have not seen the code

Sorry I have been away and I appreciate your willingness to help me out. Here is what I am trying to achieve.

I converted this URL
domainname.com/index.php?page=product&pid=5&proTitle=Samsung Galaxy

After rewrite it looks like this
domainname.com/products/5/Samsung-Galaxy.html

The code looks like this.

RewriteRule ^products/(.*)/(.*).html$  index.php?page=product&pid=$1&proTitle=$2 [nc]

Rewrite Works fine. However, if I try to access old URL i.e domainname.com/index.php?page=product&pid=5&proTitle=Samsung Galaxy the page is still accessible and on top of that being crawled by Google and other search engines. I want If someone tries to access this URL, it should direct them to Page Not Found and this should also not be sniffed by any crawlers.

Thanks a lot again for your time and I hope I can get your valuable reply soon.

RewriteRule ^products/(.*)/(.*).html$  index.php?page=product&pid=$1&proTitle=$2 [R=301,L]

I thought it was old url new url, but if this is working as expected, ok,
html status 301 permanently moved
should make SEbots and others update their links, preserve rankings,
been a while since I had to change anything, but something like "mode_rewrite 301 moved" should give a shed load of google tutorials on the exact code

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.