Simple htaccess redirection - php

I would like to create a redirection like this:
http://www.myserver.com/recipe/xxxxx.html?v1=blabla&fb_action_ids=bla&v3=blablabla
To
http://www.myserver.com/recipe/xxxx.html
Note: xxxx in the url is different according to the page.
htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^home.htm http://www.xxxxxxxxxx.co.uk/ [R=301,NC,L]
RewriteRule ^breads.htm http://www.xxxxxxxxxx.co.uk/whatwemake/ [R=301,NC,L]
RewriteRule ^cakes.htm http://www.xxxxxxxxxx.co.uk/patisserie/ [R=301,NC,L]
RewriteRule ^farmers_market.htm http://www.xxxxxxxxxx.co.uk/wheretobuy/ [R=301,NC,L]
RewriteRule ^about_us.htm http://www.xxxxxxxxxx.co.uk/ourstory/ [R=301,NC,L]
RewriteRule ^contacts.htm http://www.xxxxxxxxxx.co.uk/contact/ [R=301,NC,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(recipe/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(news/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(event/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
SetEnv APPLICATION_ENV production

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+((?:news|event|recipe)/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
RewriteRule ^ /%1? [R=302,L]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

This thing is via GET method [?v1=blabla&v2=bla&v3=blablabla] use POST then

You need a simple rewrite rule
RewriteRule ^(.*).html(.*) $1.html

Related

htaccess remove directory from full URL with string

I want htaccess to remove directory (/thedir/) from full URL but it's not working. I only want to remove the /thedir/ from this URL not other urls.
redirect 302 /thedir/?s_id=ff7d7ds7&bmt_source=facebook&bmt_camp=octy-slant&bmt_medium=ball https://example.com/?s_id=ff7d7ds7&bmt_source=facebook&bmt_camp=octy-slant&bmt_medium=ball
Also tried
RewriteCond %{QUERY_STRING} ^/thedir/?s_id=ff7d7ds7&bmt_source=facebook&bmt_camp=octy-slant&bmt_medium=ball
RewriteRule ^(.*)$ https://example.com/?s_id=ff7d7ds7&bmt_source=facebook&bmt_camp=octy-slant&bmt_medium=ball [R=302,L]
These examples do not remove /thedir/.
Try these rules in your .htaccess file.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+thedir/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^thedir/)^(.*)$ /thedir/$1 [L,NC]

how to hide folder name from url using .htaccess

I have a domain example.com i want to redirect it to example.com/public but /public folder should hide from the url.
I am using the below code in .htaccess to redirect, but unable to hide the folder name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ public [L]
Please help me out for this issue.
You can try this
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(public)
RewriteRule (.*) /public/$1
This should be your complete .htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+dirname/([^\s]+) [NC]// here you write your directory
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^dirname/)^(.*)$ /dirname/$1 [L,NC]
try this
RewriteEngine On
RewriteRule (.*) public/$ [QSA,L]

Vanity URL not working

I am using htaccess to try and rewrite a url. I have tried about 10 versions of the code and examples but nothing makes any change. I know mod_rewrite is working because it is adding www to the url, but the vanity URL won't work.
RewriteRule ^franchise/([0-9]+)/?$ franchise-information.php?franchiseid=$1 [NC,L] # Handle product requests
Here is the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^franchise/([0-9]*?)/$ franchise-information.php?franchiseid=$1 [NC,L]
</IfModule>
And here is the URL:
http://www.playballkids.com/franchise-information.php?franchiseid=162
You can use this code in your DOCUMENT_ROOT/.htaccess file:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /franchise-information\.php\?franchiseid=([^\s&]+) [NC]
RewriteRule ^ franchise/%1? [R=302,L,NE]
RewriteRule ^franchise/(\d+)/?$ franchise-information.php?franchiseid=$1 [NC,L,QSA]

rewrite from http to https results on index.php for any request

I'm using this htaccess code. I expect any call to be directed to https://www.mysite.com/theme/topic. I've really looked lots of links & helps - the result is only and ever:
https://www.example.com/index.php
so the /theme/topic are not in the output url, only the index.php
what is wrong here? thanks for any help
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
### If file exists, use it.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php [L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,QSA,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [L,QSA,R=301]
</IfModule>
you say it yourself:
so the /theme/topic are not in the output url, only the index.php
try to change the line
RewriteRule ^(.*)$ index.php [L]
into
RewriteRule ^(.*)$ /theme/topic/$1 [L]
Or is there a specific reason why not to put it there?
[edit after clarification]
So you have 2 dynamic parameters and want to rewrite yourdomain.com/parameter1/parameter2 to yourdomain.com/index.php?p1=parameter1&p2=parameter2? Then try the following:
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?p1=$1&p2=$2 [L]
[re-edit after more clarification]
Oh, so it is just redirecting from http to https and redirecting to www? Then you can just do the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC, OR]
RewriteCond %{HTTPS} !on
RewriteRule ^.*$ https://www.mysite.com/%{REQUEST_URI} [R=301,L]
</IfModule>

redirect "non-www" domain to "www"domain with .htaccess rewrite

I couldn't find the solution for "non-www" to "www" domain redirection. I have tried the following :
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
# Remove index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
</IfModule>
So, how can I redirect, for example domain.com or www.domain.com to http://www.domain.com ?.
Something like should work :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Here is what should help you:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
Can you try this ?
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Seems apache mod_rewrite module is not enabled. So Make sure the Apache module mod_rewrite is enabled on your web server.
Try again this and see..It must work.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
See here - http://iyngaran.info, It is working. So no problem with the rule
How To Create Temporary and Permanent Redirects with Apache click hear
To automatically add a www to your domain name:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
or
.htaccess To Redirect URLs
To use htaccess to redirect URL just copy and paste the snippet below and replace example.com with your domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
More info true ans
Redirecting non-www to www with .htaccess

Categories