I am new to URL rewrite, regex and .htaccess
Here is an issue I am facing:
I have this url with GET parameter:
www.mysite.in/alpha-beta/abc.php?id=APPLE%strike=200.00
I want to display it like:
www.mysite.in/alpha/beta/APPLE/200.00
This is the code in .htaccess:
RewriteRule ^alpha/beta/(.*)/([0-9]+(\.[0-9]+))$ alpha-beta/abc.php?id=$1&strike=$2 [NC,L]
But I only get a blank page when I go to URL: www.mysite.in/alpha/beta/APPLE/200.00
When I change the htaccess rule to:
RewriteRule ^alpha/beta/(.*)/([0-9]+(\.[0-9]+))$ http://www.mysite.in/alpha-beta/abc.php?id=$1&strike=$2 [NC,L]
It redirects to correct page but the URL is displayed as http://www.mysite.in/alpha-beta/abc.php?id=APPLE&strike=200.00
What seems to be the problem?
Use these rules in root .htaccess:
RewriteEngine On
RewriteRule ^OI_TOOL/IV/(.*)/([0-9]+(?:\.[0-9]+))/?$ OI_ANALYSIS_TOOL/iv_chart.php?symbol=$1&strike=$2 [NC,L,QSA]
# fix path for getIV.php by redirecting it to /OI_ANALYSIS_TOOL/
RewriteRule ^OI_TOOL/.+?/(getIV\.php)$ /OI_ANALYSIS_TOOL/$1 [L,NC,R=301]
Related
I'm trying to create a URL redirect but so far everything I have tried just hasn't shown any effect on the site. I know ModRewrite is enabled as there are other rewrites taking place. The whole purpose of this is to handle old URLs from the former version of the website.
What I want to achieve is a redirect of a URL with the following format:
/resources/view?id={id} and redirect it to /resources/{id}.
I've been trying to do so with variants of this:
RewriteRule ^resources/view?id=([0-9+])$ /resources/$1 [R=301,L]
and also this:
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^/resources/view$ /resources/$1? [R=301,L]
Cheers.
You can use these 2 rules in your site root .htaccess:
Options -MultiViews
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /resources/view\?id=(\d+) [NC]
RewriteRule ^ /resources/%1? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^resources/(\d+)/?$ resources/view?id=$1 [L,QSA,NC]
So, basically I have changed the domain name from Domain1.info to Domain2.com
Another thing that I have changed, is the rule for urls inside website
old url structure: www.Domain1.info/lang/page-name.html
new url structure: www.Domain2.com/lang/page-name
I have added the code:
RewriteEngine On
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]`
which successfully redirect me from old to new domain, but I want to get rid of the .html ending.
Basically, just exclude the .html part from the first matched group:
RewriteRule ^(.*)\.html$ http://www.domain2.com/$1 [R=301,L]`
You can tweak your regex to match only part before .html:
RewriteEngine On
# to redirect .html URLs
RewriteRule ^(.+?)\.html$ http://www.domain2.com/$1 [R=301,L,NC]
# to redirect other URLs
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]
I have a site created specific for mobiles. I added the code below into my htaccess for a redirect but it does not seem to work.
Can anyone enlighten me please
#custom redirects
RewriteEngine on
Redirect 301 /cartypes.php?cartype=12 http://m.cartypecompany.com/redcars.php
#end custom redirects
Redirect directive is not used with mod_rewrite's RewriteEngine On and you need a RewriteCond to match query string. Use this rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} =m.cartypecompany.com
RewriteRule ^redcars\.php$ /cartypes.php?cartype=12 [L,NC,QSA]
I need to redirect from page like this www.site.ru/machines/ to page www.site.ru/machines/?set_filter=y&PRICE_MIN=4500 in the mod_rewrite section of .htaccess.
You can use this rule in root .htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(machines/)$ /$1?set_filter=y&PRICE_MIN=4500 [L,NC,R]
I have dynamic URL that I want to redirect (301) with .htaccess.
Old URL:
mysite.com/index.php?route=product/search&keyword=searchphrase
New URL:
mysite.com/index.php?route=product/search&search=searchphrase
I need that the redirect will change the URL from search&keyword to search&search, but will keep the searchphrase.
How to do this?
Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(index\.php\?route=product/search)&keyword=([^\s&]+) [NC]
RewriteRule ^ /%1&search=%2 [R=301,L,NE]