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]
Related
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]
I have searched all the similar topics in the forum and nothing helped me. Here is what I am looking for:
I have a site having a login url as
site.com/folder1/php/login.php
Now I want to hide the "php" folder name from url, also remove .php extension so that it will look like
site.com/folder1/login
Also the folder name "folder1" may vary, but the folder name "php" remains the same in all urls.
Try this in your Root/.htaccess
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/?([^/]+)/([^/]+)/([^.]+)\.php [NC]
RewriteRule ^ /%1/%3 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /folder1/php/$2.php [NC,L]
This should be working.
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/+php/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^php/)^(.*)$ /php/$1 [L,NC]
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>
hello all i am having a project where i need to convert this url www.domain.com/page.php?brand=abcd to www.domain.com/abcd
i know that this is possible with .htaccess file
currently in my htaccess file i have folowing code
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.domain.com [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
ErrorDocument 404 /error404.php
ErrorDocument 403 /error404.php
Options -Indexes
please help me to do this and what line should i add to .htaccess file to achive the purpose
i tried adding
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /page.php?brand=$1 [L,QSA]
Your last rule should work for internal rewrite to /page.php?brand=abcd.
For redirecting /page.php?brand=abcd to /abcd you can use this new rule:
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+page\.php\?brand=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /page.php?brand=$1 [L,QSA]
you can Try this
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ http://litelmaxx.com%{REQUEST_URI} [R,L]
Options -Indexes
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