showing error on htaccess address rewrite - apache

i am want to convert url:
/tld/?=com to /tld/com/
my full htaccess code is as below:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+(whois|error)(?:\.php)?[\s?] [NC]
RewriteRule ^ /%1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(php?|jpg|gif|png|css|js|html|json|xml|eot|svg|ttf|woff|woff2|zip|csv|xlsx|webp|txt|gz|rar)$ [NC]
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
##### Rewite #####
##RewriteRule ^([^/]*)\$ /tld.php?tld=$1 [L]
RewriteRule ^([^/]+)\$ /tld.php?tld=$1 [L]
but its show 500 error so please help

Have it this way:
Options -Indexes -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+(whois|error)(?:\.php)?[\s?] [NC]
RewriteRule ^ /%1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(php?|jpg|gif|png|css|js|html|json|xml|eot|svg|ttf|woff|woff2|zip|csv|xlsx|webp|txt|gz|rar)$ [NC]
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]
# ignore all rules below this for files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{ENV:REDIRECT_STATUS} .
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^tld/([\w-]+)/?$ tld.php?tld=$1 [L,QSA]

Related

Combine htaccess rules

I have the following .htaccess in parent directory :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} login.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Then i have another .htaccess in a sub directory :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /mobile/new_mobile/index.html [NC,L]
Each of them separately does its job and works fine, but i want to use them both combined but cant seem to figure out how, i tried both :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /mobile/new_mobile/index.html [NC,L]
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} login.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
and
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} login.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /mobile/new_mobile/index.html [NC,L]
You can use this combined .htaccess in site root .htaccess (parent directory):
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} /login\.php [NC]
RewriteRule ^ https://%{HTTP_HOST}/%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^sub/(.*) /mobile/new_mobile/index.html [NC,L]

Remove parameters from url using .htaccess

I want to remove parameters from url,
I need change this:
http://example.com/?page=about
To this:
http://example.com/about
How?
This is my .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
Try the following in htaccess :
RewriteEngine On
#Remove php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/?$ /$1.php [NC,L]
#rewrite /about to /?page=about
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /?page=$1 [NC,L]
this will rewrite
/about
to
/?page=about
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1 [QSA,L]

add rule to convert ? and & by / htaccess

ErrorDocument 404 /error404.php
ErrorDocument 403 /error404.php
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} POST [NC]
RewriteRule ^ - [L]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC]
RewriteRule \.(gif|jpg|jpeg)$ http://www.domain.com [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(profile)\.php\?eid=(78)[&\s] [NC]
RewriteRule ^ /%1/%2? [R=301,L]
RewriteRule ^(profile)/(\d+)$ /$1.php?eid=$2 [L,QSA,NC]
RewriteCond %{THE_REQUEST} \s/+enterprise\.php\?url=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /enterprise.php?url=$1 [L,QSA]
everything i right til now but one thing that i want from the site is that to direct the following link http://www.domain.com/profile?eid=1 to this link http://www.domain.com/eid/1
please help this is something very imp
and also tell me if it is possible to replace all the ? and & and = by / in the url
Have your rules like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} POST [NC]
RewriteRule ^ - [L]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC]
RewriteRule \.(gif|jpg|jpeg)$ http://www.domain.com [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# redirect /profile?eid=1 to /eid/1
RewriteCond %{THE_REQUEST} \s/+profile(?:\.php)?\?(eid)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
# internally rewrite /eid/1 to /profile.php?eid=1
RewriteRule ^(eid)/(\d+)$ profile.php?$1=$2 [L,QSA,NC]
RewriteCond %{THE_REQUEST} \s/+enterprise\.php\?url=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ enterprise.php?url=$1 [L,QSA]

URL Friendly using htaccess

Having the below urls, but only the first one works with my htaccess code. Please help to fix this for both url at time. Thank you.
URL 1: http://domain.com/index.php?id=Apple
Output : http://domain.com/Apple (This is ok)
URL 2: http://domain.com/index.php?id=Apple-Board&jid=Chief-Accountant
Output : http://domain.com/Apple-Board (This is not ok)
Expected Output : http://domain.com/Apple-Board/Chief-Accountant
Options -Multiviews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/?$ index.php?id=$1 [B,L]
RewriteRule /id/(.*)/jobid/(.*)/ index.php?id=$1&jid=$2
You can use:
Options -Multiviews
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+index\.php\?id=([^\s&]+)&jid=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]
RewriteCond %{THE_REQUEST} \s/+index\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ index.php?id=$1 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?id=$1&jid=$2 [L,QSA]

How to exclude a subdirectory from an Apache URL rewrite condition

I have the following rewrite conditions applied to the root directory of my Apache2 webserver (in apache.conf)
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_ADDR} !=127.0.0.1
RewriteCond %{SERVER_ADDR} !=::1
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule "(^|/)\." - [F]
</IfModule>
I have a subdirectory, www.domain.com/subdir that I don't want these rewrites to apply to. How can I exclude subdir from these options?
Actually you just need to move up your last rule of skipping files/directories. Try this code:
Options +FollowSymlinks
RewriteEngine On
# if request is not for a file/directory
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
# then skip from rewrites
RewriteRule ^ - [L]
# add www to hostname
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_ADDR} !=127.0.0.1
RewriteCond %{SERVER_ADDR} !=::1
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# forward all the requests to `/index.php
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Right after this line
RewriteEngine On
Add:
RewriteRule ^/subdir/ - [L]
or
RewriteCond %{THE_REQUEST} \ /+subdir/
RewriteRule ^ - [L]