Multiple conflicting htaccess RewriteRules - .htaccess

I'm trying to have both people's profiles at example.com/Sara and a few special pages like example.com/home and /account.
How do I make both of my RewriteRules work?
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./people.php?s=$1
RewriteRule ^home ./home.php
Thanks!
Edit:
Figured it out...!
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./people.php?s=$1

Figured it out...!
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./people.php?s=$1

Related

How to rewrite the website URL in .htaccess

is there a way to replace an url with the .htaccess like this:
http://website.com/file.php?watch=video
to this one:
http://website.com/file/watch/video
Tried with this,and haven't worked.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/watch/([\d]+)$ $1.php?watch=$2 [L]
My .htaccess file:
#remove php file extension-e.g. https://example.com/file.php will become
https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/watch/([\w-]+)$ $1.php?watch=$2 [L]
Have it this way:
RewriteEngine on
RewriteBase /test/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /([\w-]+)\.php\?watch=([^\s&]+)\s [NC]
RewriteRule ^ %1/watch/%2? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/watch/([\w-]+)$ $1.php?watch=$2 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

how to merge these two .htaccess files?

I would like to merge these two htaccess files.
RewriteEngine On
RewriteCond %{HTTP:HOST} http://example.io/
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule ^$ http://example.io/es/[L,R=301]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ http://example.io/en/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(en|es)/?$ [QSA,NC,L]
and this other one
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
any ideas on how to do this? thank you very much
Have you tested this? It seems a logical starting point. It should catch your special "not a file" case before moving on to the catch-all you have at the bottom.
RewriteEngine On
RewriteCond %{HTTP:HOST} http://example.io/
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule ^$ http://example.io/es/[L,R=301]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ http://example.io/en/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(en|es)/?$ [QSA,NC,L]

subdomains linked to different files using htaccess

I'm trying to create redirect to different files for different subdomains, maybe domains in the future. This is based on ModX CMS.
I want to keep url the same, just run different file for each subdomain, passing some data. For domain.com it's index.php, for sub1.domain.com - sub1.php. Also I want to pass some data, you can see it in the example below:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub1\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub1.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub2\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub2.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub3\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub3.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub4\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub4.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub5\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub5.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub6\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub6.php?q=$1 [L,QSA]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I tried to # last 3 lines, but it didnt make any difference. I've got more lines in htaccess, but they are #. Subdomain I create in control panel of my server, all subdomains are ponted to the same directory (public_html).
Right now I'm not sure passing data works, and when I go to sub1.domain.com apache redirect me to www.domain.com/sub1.php, thich is wrong.
How do I link subdomains to their php files and keep url the same (sub1.domain.com)??
Remove redundant stuff and keep your code like this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub1\.domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /sub1.php?q=$1 [L,QSA]

How to rewrite rules for two subfolders using mod_rewrite

I would need to do something like this:
########## SITE 1
RewriteEngine on
RewriteBase /mysite1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
########## SITE 2
RewriteEngine on
RewriteBase /mySecondSite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
The problem is that i can only use one .htaccess file as I am using Helicon ISAPI_Rewrite 3 over windows 2003 Server.
Is there a way to combine both .htaccess files in just one of them and making them work properly?
I have tried this just to test if mysite would work without the RewriteBase, but seems not to work:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^mysite1/(.*)$ index.php?url=$1 [L,QSA]
Thanks.
than I can't come up with anything better than this:
########## SITE 1
RewriteEngine on
RewriteCond %{HTTP:Host} ^www\.website\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mysite1/index.php?url=$1 [L,QSA]
########## SITE 2
RewriteEngine on
RewriteCond %{HTTP:Host} ^www\.demo\.website\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mySecondSite/index.php?url=$1 [L,QSA]
In case the names of your folders are the same as the names of the sites:
RewriteEngine on
RewriteCond %{HTTP:Host} ^www\.([^.]+)\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /%1/index.php?url=$1 [L,QSA]
Finally I did it like this:
RewriteEngine on
RewriteBase /
########## SITE 1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^site1/(.*)$ site1/index.php?url=$1 [L, QSA]
########## SITE 2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^site2/(.*)$ site2/index.php?url=$1 [L, QSA]
########## SITE 3 (by URL)
RewriteCond %{HTTP_HOST} ^mysite3.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mysite3.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L, QSA]

Htaccess Problem in PHP

How can I rewrite
www.example.com/test.php?search=demo
to
www.example.com/test/?search=demo
using htaccess
Put that into your .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9]+)/?$ $1.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Resources