How to write two different rules in one .htaccess file? - php

I want to write these two different rules in one file. How I have to do it?
RewriteEngine On
RewriteCond %{REQUEST_URI} /v0\.3/forum/
RewriteRule ^(.*)$ /v0.3/test.php?forum=$1 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_URI} /v0\.3/profile/
RewriteRule ^(.*)$ /v0.3/profiles.php?id=$1 [L,QSA]

Simply delete the second RewriteEngine On declaration
RewriteEngine On
RewriteCond %{REQUEST_URI} /v0\.3/forum/
RewriteRule ^(.*)$ /v0.3/test.php?forum=$1 [L,QSA]
RewriteCond %{REQUEST_URI} /v0\.3/profile/
RewriteRule ^(.*)$ /v0.3/profiles.php?id=$1 [L,QSA]

Related

REWRITE URL and keep QUERY STRING in .htaccess

Here is my .htaccess code...
ErrorDocument 404 /404.html
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !\.php$
RewriteCond %{REQUEST_URI} !\.css$
RewriteCond %{REQUEST_URI} !\.js$
RewriteCond %{REQUEST_URI} !\.png$
RewriteCond %{REQUEST_URI} !\.mp3$
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteCond %{REQUEST_URI} !\.html$
RewriteCond %{REQUEST_URI} !\.xml$
RewriteCond %{REQUEST_URI} !\.txt$
RewriteCond %{REQUEST_URI} !\.gif$
RewriteRule ^(.*)$ /$1.php [L]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com" [R=301,L]
I want to have: example.com/buy?r=abc123 appear like: example.com/release/abc123 or even like: example.com/abc123
I cannot $_GET the contents of r in buy.php once the url has been redirected.
I hope someone can help :)
If you want clean URLs then you can simply use:
RewriteRule ^([^/]*)$ /buy?r=$1 [L]
to get example.com/abc123
Or you can use:
RewriteRule ^release/([^/]*)$ /buy?r=$1 [L]
to get example.com/release/abc123.
Just make sure you clear your cache before testing this.

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]

Hide directory name from URL by .htaccess

When user types:
www.domain.com/standard/Public/Modules/home.php or
www.domain.com/standard/Public/Modules/contacts.php
(or anything that follows the same pattern)
I want the URL to be displayed like this:
www.domain.com/home
www.domain.com/contacts
...
My current .htaccess:
RewriteEngine on
RewriteRule ^home.php/?$ standard/Public/Modules/home.php [NC,L]
RewriteRule ^contacts.php/?$ standard/Public/Modules/contacts.php [NC,L]
You need to have this in your root .htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} /standard/Public/Modules/login\.php [NC]
RewriteRule ^standard/Public/Modules/login\.php$ /home [L,NC,R=301]
RewriteCond %{THE_REQUEST} /standard/Public/Modules/logout\.php [NC]
RewriteRule ^standard/Public/Modules/logout\.php$ /contacts [L,NC,R=301]
RewriteRule ^home/?$ /standard/Public/Modules/login.php [NC,L]
RewriteRule ^contacts/?$ /standard/Public/Modules/logout.php [NC,L]
I use this, no need to individually set rewrites for pages
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
For example
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)-product(.*).html$ /products/view/$2 [L]
RewriteRule ^(.*)-cat(.*).html$ /products/listing/$2 [L]
RewriteRule ^products.html$ /products/listing/ [L]
RewriteRule ^bioproducts.html$ /products/bio_listing/ [L]
RewriteRule ^aboutus.html$ /static/index/15 [L]
RewriteRule ^contacts.html$ /static/contacts [L]
RewriteRule ^(.*)-partners(.*).html /partners/index/$2 [L]
</IfModule>

working with symbolic link before the controller/method in codeigniter

i just needed some help i think its about time to ask some good felas for help.
here's my situation, i've been trying to use a symbolic link to fake my url just like this.
www.website.com/uk/controllers/method/etc
www.website.com/us/controllers/method/etc
aparently codeigniter failes to read the controller. the uk and us segment is a symlink to root directory so I expect it should point that to root. what made me sure that it points to the root is by viewing www.website.com/uk/ it works fine no erros all good. please help me on how to fix this. it might be i'm missing something like in htaccess or in route file. i've been having a headache about this for a day.
here's my current htaccess contents
Options FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} /index\.(php|html)
RewriteRule (.*)index\.(php|html)(.*)$ $1$3 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I'm not sure if this will help but if you are using language class, then have a look at this extention:
https://github.com/EllisLab/CodeIgniter/wiki/URI-Language-Identifier
Try this code for redirecting /us/ and /uk/ to root:
Options FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} /index\.(php|html)
RewriteRule (.*)index\.(php|html)(.*)$ $1$3 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_URI} ^(system|application)
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteRule ^(?:us|uk)/(.*)$ /$1 [L,NC,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

properly structuring an htaccess with multiple rules/conds

How would i properly structure this htaccess file as to correctly function in order and avoid infinite loops?
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
RewriteBase /
RewriteRule ^deviceToken/$ devicetoken.php [QSA,L]
RewriteRule ^register/$ register.php [QSA,L]
RewriteRule ^resetPassword/$ resetpassword.php [QSA,L]
RewriteRule ^deleteLink/$ deletelink.php [QSA,L]
RewriteRule ^getLinks/$ getlinks.php [QSA,L]
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)|(\.swf)|(\.xpi)|(\.ico)|(\.src)$
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule (.*)$ get.php?code=$1 [L]
It looks OK, have you tried it already?
This line is useless:
RewriteCond %{REQUEST_URI} ^(.*)$
Redirect domain first:
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
(added ,L)

Categories