I try made my url friendly:
https://xxxxx.com/imovel?apartamento-cangaíba-são+paulo-73+m²
to
https://xxxxx.com/imovel/apartamento-cangaíba-são+paulo-73+m²
Need change ? to /
My apache ssl file configuration is:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^33\.333\.33\.33$
RewriteRule ^(.*)$ https://xxxxx.com [L,R=301]
# To remove trailing slash
# RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)/$ $1 [R=301,L]
# To remove .php extension
RewriteRule ^(.*)\.php$ $1 [R=301,L]
# To check whether the file exists then set it back internally
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.php -f
RewriteRule ^.*$ $0.php [L]
#Seo imovel
RewriteRule ^imovel/([a-z0-9-]+)/?$ /imovel?titulo=$1 [NC]
I only need now change the ? to /.
In my action form:
<form id="f_det" method="post" action="imovel?<?php echo strtolower(urlencode($imovels->tipo_imob."-".$imovels->bairro_imob."-".$imovels->cidade_imob."-".$tam_m2));?>">
Cant find my mistake. Dont work on the end url is like:
https://xxxxx.com/imovel?apartamento-cangaíba-são+paulo-73+m²
Please change your action url imovel? to imovel/, like below,
<form id="f_det" method="post" action="imovel/<?php echo strtolower(urlencode($imovels->tipo_imob."-".$imovels->bairro_imob."-".$imovels->cidade_imob."-".$tam_m2));?>">
Related
Hello i am facing issue to remove the public/index.php from url. Remove/Redirect index.php from url to prevent duplicate urls
This link really helps me to remove index.php form url but i am not able to remove public/index.php from url. Here is my below htacces code
RewriteEngine On
#REmove index.php from url starts
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php[^/] /$1? [L,R=302,NC,NE]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2? [L,R=302,NC,NE]
#Remove index.php from url ends
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
But when i add this below code to remove public/index.php in htaccess its not working :-
RewriteCond %{THE_REQUEST} /public/index\.php [NC]
RewriteRule ^(.*?)public/index\.php[^/] /$1? [L,R=302,NC,NE]
RewriteCond %{THE_REQUEST} /public/index\.php [NC]
RewriteRule ^(.*?)public/index\.php(?:/(.*))?$ /$1$2? [L,R=302,NC,NE]
Example urls that should be redirected:
mydomain.com/public/index.php/something should be redirected to mydomain.com/something (something could be anything - can contain any characters)
mydomain.com/public/index.php should be redirected to mydomain.com
mydomain.com/index.php?anything should be redirected to mydomain.com?anything (anything can contain any characters)
Pleae help me how to resolve this issue.
You may use this rule inside public/.htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /public/index\.php(?:[/?](\S+))?\sHTTP [NC]
RewriteRule ^ /%1 [L,R=301,NE]
RewriteCond %{THE_REQUEST} /public/(\S*)\sHTTP [NC]
RewriteRule ^ /%1 [L,R=301,NE]
# other rules below this line
Additionally use this code in site root .htaccess:
RewriteEngine On
# remove /index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ %1 [L,R=301,NE]
RewriteRule ^ public%{REQUEST_URI} [L]
I've tried several solutions but none of them seem to work. I have a Laravel application(public folder is removed) and i wanted to redirect the user to HTTPS and a non-www version of my website
Here is an example of the action i wanted to accomplish
Redirect http://example.com to https://example.com
Redirect http://www.example.com to https://example.com
Redirect https://www.example.com to https://example.com
I was able to accomplish that using the following code on htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example.com$ [NC]
RewriteRule (.*) https://example.com [R=301,L]
Now, since the website has many links, i wanted to redirect the users without losing any text after the domain. Here is an example
Redirect https://www.example.com/electronics/laptops/hp to https://example.com/electronics/laptops/hp
I tried many variations using $ and request_uri but they keep redirecting to https://example.com/index.php. After searching for answers here, the last thing i tried looked something like this, which yielded the same result
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%1%{REQUEST_URI} [L,R=301,NE]
This seems to redirect any traffic that comes as https://www.example.com/string1/string2/string3 to https://example.com/index.php
So how can i redirect traffic as intended and which is a better practice. Write two rules or combine the rules using If statements.
I would like to use htaccess only methods, no middleware.
I had the same problem
You should put this code on top of .htaccsee file after
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://yourdoamin.com%{REQUEST_URI} [L,R=301,NC]
if you put this after
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
your page redirect to yourdomain.com/index.php
To redirect www requests to non-www without losing the path or the query string this is the right format:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule (.*) https://example.com/$1 [R=301,L]
If your website is on a server without a reverse proxy, you can easily redirect non-HTTPS requests to HTTPS as following:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
In case there is a reverse proxy or a load balancer you need to check the forwarded headers, depending on the proxy configuration (eg. X-Forwared-Proto)
Try out this one
# Redirect from http to https
RewriteEngine on
# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# (http://www.example.com/foo will be redirected to http://example.com/foo)
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
# to redirect index.php to the root
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
I had the same problem
You should put this code on top of .htaccsee file after
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://yourdoamin.com%{REQUEST_URI} [L,R=301,NC]
if you put this after
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
your page redirect to yourdomain.com/index.php
After spending a few hours searching the web and testing different suggestions, I found the solution.
.htaccess in the public_html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
.htaccess in the public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Redirect to https
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R,L]
# Redirect to non www
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$ [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# This made the trick for me
# Remove index.php from the url
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
</IfModule>
I hope this will work for others too
I tried this:
RedirectMatch 301 (.*) http://olddomain.com$1
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^olddomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]
But all subpages are not redirected.
Try this,
RewriteEngine On
# Take care of www.old.com.au
RewriteCond %{HTTP_HOST} ^www.old.com.au$ [NC]
RewriteRule ^(.*)$ http://www.new.com/$1 [L,R=301]
RewriteCond %{QUERY_STRING} ^attachment_id=([0-9]*)$ [NC]
RewriteRule ^$ http://www.new.com/? [R=301,NE,NC,L]
It's simple, I was just using this to do some special rewriting for my own, here is your code:
Put this inside your /www/.htaccess file:
RewriteEngine on
// Rules to redirect to another domain
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]
Check http://www.inmotionhosting.com/support/website/redirects/setting-up-a-301-permanent-redirect-via-htaccess, for 3 more ways to make a redirection.
Are you setting directive AllowOverride All in your Apache config?
Is the mod_rewrite module working?
If a query string is detected, I want to update/set a cookie so a particular dir is used for that browser session or until the query string is explicitly set again. Visitor is not to see the dir, but instead will just see http://mydomain.com/.
This is what I have so far but it doesn't work as expected. Pretty sure I'm writing the logic wrong, but not sure where.
RewriteCond %{QUERY_STRING} splittest=(A|B)
RewriteRule splittest=(A|B) [CO=splittest:$1:%{HTTP_HOST}:0:/,L]
RewriteCond %{QUERY_STRING} splittest=A [OR]
RewriteCond %{HTTP_COOKIE} splittest=A
# Split test A
RewriteRule ^(.*)$ A/$1 [L]
# Split test B
RewriteRule ^(.*)$ B/$1 [L]
Try this. I'm assuming your .htaccess is located at web root / directory.
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} splittest=A [NC]
RewriteRule ^ - [CO=splittest:A:%{HTTP_HOST}:0:/]
RewriteCond %{QUERY_STRING} splittest=B [NC]
RewriteRule ^ - [CO=splittest:B:%{HTTP_HOST}:0:/]
RewriteCond %{QUERY_STRING} splittest=A [NC,OR]
RewriteCond %{HTTP_COOKIE} splittest=A [NC]
# Split test A
RewriteRule ^(.*)$ A/$1 [L]
# Split test B
RewriteRule ^(.*)$ B/$1 [L]
EDIT: I must add something.First of all i want to change url display because of SEO.If i use www for reach my website there is no problem, second link is appears and everything is ok.
But if i remove "www" from link, it changing to first url and i doesn't want that.
I want to change
http://www.mysite.com/index.php?route=epson-claria-uyumlu-yazici-kartus-dolum-murekkebi-500g.html
to
http://www.mysite.com/epson-claria-uyumlu-yazici-kartus-dolum-murekkebi-500g.html
how I can do it?
I tried
RewriteCond %{QUERY_STRING} ^_route_=(.*)$
RewriteRule ^index\.php$ /%1 [R=301,L]
but it is not working.
My .htaccess is
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteRule ^index\.php$ http://www.mysite.com? [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
Maybe this is what you're looking for:
RewriteRule ^(.*)$ index.php?route=$1 [L]
If you have to visually change the address bar, leave the RewriteRule in place as I described above, and put this in your index.php before any output:
if(isset($_REQUEST['route']))
{
header('Location: '.urlencode($_REQUEST['route']));
}
Initial note: I'm not an Apache guru so don't rely blindly on my answer.
I would first redirect to www. if required
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{SERVER_NAME}/$1 [R=301,L]
Then make it go to the page indicated by the _route_ query variable
# if it is the index page...
RewriteCond %{REQUEST_URI} ^/(index\..+)?$ [NC]
# and if the query string starts with _route_=
RewriteCond %{QUERY_STRING} ^_route_=(.*)$
# redirect
RewriteRule ^(.*)$ http://%{SERVER_NAME}/%1? [R=301,L]
Server variable SERVER_NAME in last line might need to be changed with HTTP_HOST.