Remove URL parameter htacces - .htaccess

I need to remove a parameter in some cases from URL.
The working url's are:
mywebpage.com/es/apartments/ or mywebpage.com/es/apartments/apartment1/
But some time I need to pass a value and get url like this:
mywebpage.com/es/apartments/&param=12345/
In this cases, the page are redirected to 404 page.
The code that I have in htaccess refered to this for redirect from other page is:
RewriteCond %{QUERY_STRING} ^luxury-apartments/$
RewriteRule ^error404.php$ /es/apartments/? [L,R=301]
How I can remove this param and don't get a 404 redirect? I try some codes, but always redirect me to 404 page.

Related

htaccess do not redirect if url is wrong

http://www.test.com/test/test2/dresses.html
When I call this URL, I want to redirect as below:
RewriteRule ^test/test2/(.*).html /index.php?dir=category&action=$1 [QSA]
but some of the URL like http://www.test.com/test/test2/bad.html does not exist and it displays a 404 page so I don't want to redirect bad URL and is that possible?

Joomla redirect 403

I need to redirect from http://mysite/component/users to main page
i tried this rule in .htaccess but code not working.
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule http://mysite/component/users/ index.php [F]
but i need to keep from redirecting this page
http://mysite/component/users/?view=reset
it's possible ?
There's a couple of things fundamentally wrong with your RewriteRule:
When you use the F flag you can't rewrite the URL. The substitution is ignored.
The RewriteRule pattern is a regular expression and matches against the URL-path, not the absolute URL.
In order to return a 403 and display the appropriate content, you could either:
Internally rewrite to index.php and conditionally return a 403 Forbidden header.
or
Serve your 403 error document (using the F flag) and conditionally show your content?
However, I would simply serve the appropriate 403 error document and link to the homepage. The request is after all forbidden....
RewriteCond %{QUERY_STRING} !^view=reset
RewriteRule ^component/users/ - [F]
The above sends a 403 to all requests for URLs that start /component/users/, excluding those that have the query string view=reset.

redirecting page to 404

I've found a few pages for redirecting a single page to 404 but it's not working. Here is my simple line
RedirectMatch 404 ^/showthread.php?p=3164554$
It does not work though. Am I missing something? Thanks!
Your configuration tries to redirect the page "404" to the page "^/showthread.php?p=3164554$" (see the documentation).
RedirectMatch generates a redirection : you can't redirect with a HTTP 404 code. When redirecting, you may have issues with the query string (I couldn't match the query string), I would use rewrite rules :
You can redirect to a 404.html page with
RewriteEngine On
RewriteCond %{QUERY_STRING} p=3164554
# the empty question mark discard the query string
RewriteRule ^/showthread\.php 404.html? [L,R=301]
Or you can stay on the same url but show the 404 page :
RewriteEngine On
RewriteCond %{QUERY_STRING} p=3164554
RewriteRule ^/showthread\.php - [L,R=404]
Try this way to escape your . character with \ like this.Let me know, it works for you or not.
RedirectMatch 404 ^/showthread\.php?p=3164554$

301 redirect with ? (question mark) not working in htacces

This is probably an easy question, but we can not find why the 301 is not working. When we have a url with a question mark the 301 redirect in our .htacces is not working. For example:
/order/order.html?AddID=1078&Rand=666171759380936096
so:
Redirect 301 /order/order.html?AddID=1078&Rand=666171759380936096 http://www.domain.nl
In our webmaster tools we have 8000 url's with the same structure /order/order.html?AddID=.... that say 404 not found. We want to 301 redirect them to the homepage, but we get a 404 not found page instead. when we use the same redirect with only /order/order.html he is redirected correct.
You can't match against the query string in a Redirect statement, use mod_rewrite and match against the %{QUERY_STRING} var:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^AddID=1078&Rand=666171759380936096$
RewriteRule ^order/order.html$ http://www.domain.nl/? [L,R=301]
But since you have like 8000 URLs that start with the query string ?AddID=, then you can just match against that:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^AddID=[0-9]
RewriteRule ^order/order.html$ http://www.domain.nl/? [L,R=301]
I have just tried it again and now I placed it right in the top of the htacces, see printscreen. In this case it is about the url (normally I do not place my own url) www.tablet.nl and if you place one of our 404 pages /order/order.html?AddID=1037&Rand=539054443213186002 behind the url, /order/order.html is deleted and only ?AddID=1037&Rand=539054443213186002 is shown behind the main url with a 404 page not found.
Any idea and I let the htacces as shown in the attachement so you can test the url.
Let me know

How to pass URL Parameters through a .htaccess file

I need to transparently pass a URL parameter through a .htaccess 301 redirection but I am unfamiliar with how to code it.
For example, an Adwords clickthrough appends the following parameter to the landing page url:
&gclid=CKCPq62Sq6wCFY1S4god4FZd1g
Our Google landing page is being redirected like this:
Redirect 301 /old-page /new-page
(We don't want to edit our Google Ads as doing so would lose our existing stats. Thus the redirect..)
How do I preserve the above gclid parameter while redirecting in .htaccess?
Thanks,
Geoff
You can't handle dynamic query strings properly with standard htaccess 301 redirect. In order to do so you should use mod_rewrite:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule /old-page /new-page?%{QUERY_STRING} [R=301,L]
See, http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
NOTE: I'm not positive that RewriteCond is required, but it's there to prevent the page from redirecting over and over again. Depending on the rest of the layout of your site, you may need it... although in most cases it's not needed unless you're redirecting all requests.

Resources