so i have loads of domain names on 1 hosting plan but have a main one in my root i am using http acess
options -multiviews
options All -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^home$ index.php
RewriteRule ^dashboard$ dashboard.php
RewriteRule ^advertiser$ advertiser.php
RewriteRule ^add_campaign$ add_campaign.php
RewriteRule ^edit_campaign$ edit_campaign.php
RewriteRule ^stats$ view_statistics.php
RewriteRule ^login$ login.php
RewriteRule ^logout$ logout.php
RewriteRule ^withdrawals$ withdrawals.php
RewriteRule ^register$ register.php
RewriteRule ^report$ report.php
RewriteRule ^referrals$ referrals.php
RewriteRule ^contact$ contact.php
RewriteRule ^add_wallet$ add_wallet.php
RewriteRule ^payment_page$ payment_page.php
RewriteRule ^forgot_password$ forgot_password.php
RewriteRule ^my_account$ my_account.php
RewriteRule ^(admin)($|/) - [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ view_link.php?s=$1 [L]
RewriteRule ^page_([^/]+)/?$ pages.php?slug=$1 [L]
</IfModule>
The rest of my domain names will now not work because it will not let me access any of the files by doing domainname.com/folder is there any way to set these rules just for the main domain name??
Try to add RewriteCode that matches the main domain name. Like this
options -multiviews
options All -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourmaindomain.com$
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^home$ index.php
RewriteRule ^dashboard$ dashboard.php
RewriteRule ^advertiser$ advertiser.php
RewriteRule ^add_campaign$ add_campaign.php
RewriteRule ^edit_campaign$ edit_campaign.php
RewriteRule ^stats$ view_statistics.php
RewriteRule ^login$ login.php
RewriteRule ^logout$ logout.php
RewriteRule ^withdrawals$ withdrawals.php
RewriteRule ^register$ register.php
RewriteRule ^report$ report.php
RewriteRule ^referrals$ referrals.php
RewriteRule ^contact$ contact.php
RewriteRule ^add_wallet$ add_wallet.php
RewriteRule ^payment_page$ payment_page.php
RewriteRule ^forgot_password$ forgot_password.php
RewriteRule ^my_account$ my_account.php
RewriteRule ^(admin)($|/) - [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ view_link.php?s=$1 [L]
RewriteRule ^page_([^/]+)/?$ pages.php?slug=$1 [L]
</IfModule>
Then the rewrite rules should only run if the domain matches.
Related
I am trying to rewrite my page like abc.com/profile.php?id=abc to abc.com/abc
Can you guide me?
When I try to add the following line, i getting 500 page error
RewriteRule ^([^/]*)$ /profile.php?id=$1 [L]
my htaccess
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /detail.php?type=$1&title=$2&id=$3 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?pn=$1&type=$2 [L]
RewriteRule ^contact-us.html$ contact-us.php [NC,L]
RewriteRule ^about-us.html$ /about-us.php [NC,L]
RewriteRule ^privacy-policy.html$ /privacy-policy.php [NC,L]
RewriteRule ^legal.html$ /legal.php [NC,L]
RewriteRule ^search$ /search.php [NC,L]
RewriteRule ^disclaimer.html$ /disclaimer.php [NC,L]
RewriteRule ^submit-job$ /submit-job.php [NC,L]
I am building a website with two main sections,
so I have created two subdomains:
web1.example.com
web2.example.com
since i'm building websites with codeigniter, I want to redirect to the index.php page. here's what I did:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/web1 [R=301,NC,L]
it works as expected, but it changes the url to example.com/web1..
is there any way to keep the url web1.example.com, but still redirecting to example.com/web1?
I already am using .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
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]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
when I enter web1.example.com, the actual url to be executed should be:
example.com/web1, and file to be executed is index.php ..
Didnt tested, Modify and try this
RewriteRule ^([a-zA-Z0-9-/]+).example.com$ http://example.com/$1 [L]
RewriteRule ^([a-zA-Z0-9-/]+).example.com/([a-zA-Z0-9-/]+) http://example.com/$1&$2 [L]
Edited 1
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/index.php/%1&$1 [L,NC,QSA]
I have made a php web application which uses links like :
Link
... onClick="window.location.href='/asset/image.ext'" ...
<? header("Location: /login"); ?>
etc.
As you might have noticed, almost EVERY link starts with /.
Many links are rewritten in .htaccess like this :
Options All -Indexes
RewriteEngine on
RewriteRule ^login/error_418$ assets/common/login.php?&error [L]
RewriteRule ^login$ assets/common/login.php [L]
RewriteRule ^settings/change-profile-picture$ index.php?page=settings&command=profilePicture [L]
RewriteRule ^settings/change-password/error-requirements$ index.php?page=settings&command=password&error=requirements [L]
RewriteRule ^settings/change-password/error-missmatch$ index.php?page=settings&command=password&error=missmatch [L]
RewriteRule ^settings/change-password/error-418$ index.php?page=settings&command=password&error=418 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/grades$ index.php?page=grades&course=$1 [L]
Now I need to move it on a web server where it will NOT be in the root direcotry but in a folder...
How do I now redirect all the root links to that folder ?
First place your existing rule in /folder/.htaccess like this:
Options All -Indexes
RewriteEngine on
RewriteBase /folder/
RewriteRule ^login/error_418$ assets/common/login.php?&error [L]
RewriteRule ^login$ assets/common/login.php [L]
RewriteRule ^settings/change-profile-picture$ index.php?page=settings&command=profilePicture [L]
RewriteRule ^settings/change-password/error-requirements$ index.php?page=settings&command=password&error=requirements [L]
RewriteRule ^settings/change-password/error-missmatch$ index.php?page=settings&command=password&error=missmatch [L]
RewriteRule ^settings/change-password/error-418$ index.php?page=settings&command=password&error=418 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/grades$ index.php?page=grades&course=$1 [L]
Then create a rule in root .htaccess as this:
RewriteEngine On
RewriteBase /
RewriteRule ^((?!folder/).*)$ folder/$1 [L,NC]
i have such files:
index.php
<?php
echo $_REQUEST['cat_id'];
echo "***";
echo $_REQUEST['page'];
?>
and .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^ru/ index.php
RewriteRule ^ua/ index_ua.php
RewriteRule ^ru/(.*)/ index.php?cat_id=$1
RewriteRule ^ua/(.*)/ index_ua.php?cat_id=$1
RewriteRule ^ru/(.*)/([0-9]+)/ index.php?cat_id=$1&page=$2
RewriteRule ^ua/(.*)/([0-9]+)/ index_ua.php?cat_id=$1&page=$2
RewriteRule ^(.*)/ index.php?cat_id=$1
RewriteRule ^(.+)/([0-9]+)/ index.php?cat_id=$1&page=$2
</IfModule>
http://site2.com/ru/stranica/2/
shows:
index.php/stranica***2
http://site2.com/ru/stranica/
shows:
index.php/stranica***
http://site2.com/ru/
shows:
index.php***
Why $_REQUEST['cat_id'] show index.php, instead stranica ? Thanks!
It is because your regex is using greedy .* pattern and not using anchors where it is needed.
You can use these rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ru/?$ index.php [L,QSA]
RewriteRule ^ua/?$ index_ua.php [L,QSA]
RewriteRule ^ru/([^/]+)/?$ index.php?cat_id=$1 [L,QSA]
RewriteRule ^ua/([^/]+)/?$ index_ua.php?cat_id=$1 [L,QSA]
RewriteRule ^ru/([^/]+)/([0-9]+)/?$ index.php?cat_id=$1&page=$2 [L,QSA]
RewriteRule ^ua/([^/]+)/([0-9]+)/?$ index_ua.php?cat_id=$1&page=$2 [L,QSA]
RewriteRule ^([^/]+)/([0-9]+)/?$ index.php?cat_id=$1&page=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?cat_id=$1 [L,QSA]
</IfModule>
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>