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]
Related
I have created my own .htaccess file which purpose is to change the username URL of my site (along with remove the .php extension from all urls).
The intent is for the URL to transform from:
www.example.one/profile.php?id=username
to
www.example.one/username
I know this is a common problem with "username" htaccess rewrites, however, none of the answers I have found have helped me solve my problem.
This is my full .htaccess:
Options -Indexes
Options +FollowSymLinks
RewriteEngine On
# only allow rewriting to paths that dont exist
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
# redirect example.one to www.*
RewriteCond %{HTTP_HOST} ^example\.one$ [NC]
RewriteRule ^(.*)$ http://www.example.one [R=301,L]
# no php extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# example.one/username
RewriteRule ^/([a-zA-Z_\-0-9]+)*$ ./profile.php?id=$1
Cheers.
You may use these rules in your site root .htaccess:
Options +FollowSymLinks -Indexes
RewriteEngine On
# redirect example.one to www.*
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /profile\.php\?id=([\w-]+) [NC]
RewriteRule ^ /%1? [R=301,L]
# no php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# example.one/username
# only allow rewriting to paths that dont exist
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/?$ profile.php?id=$1 [L,QSA]
How can I Hide index.php and rewriting URL parameters
http:example.com/www/index.php?page=admin&action=login
as
http:example.com/www/admin/login
I have hide index.php using the code mentioned below (Helped from URL) which makes URL as:
http:example.com/www/?page=admin&action=login
My htaccess file code
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
But I need like this:
http:example.com/www/admin/login
If any body knows, that will be a great help.Thank you
You can use these rules in /www/.htaccess:
DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /www/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&action=$2 [L,QSA]
RewriteRule ^(.+)$ index.php?$1 [L,QSA]
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 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]
I try to make the URL of my site a litle more readable, but I have trouble doing this.
Her are samples of the URL it Looks like now:
http://example.com/
http://example.com/index.php
http://example.com/index.php?page=home
http://example.com/index.php?page=profile&uid=483ec3a0-7e0f-32e6-f357-ac9311204246
They have to look like:
http://example.com/
http://example.com/home/
http://example.com/profile/483ec3a0-7e0f-32e6-f357-ac9311204246/
Here is the Content of my .htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# external redirect from /view.php?id=1 to /view/id/1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+)&uid=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/? [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1/? [L,R=301]
# internal forward from /view/id/1 to /view.php?id=1
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?page=$1&uid=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]
It rewrites correct an URL like http://example.com/index.php?page=profile&uid=483ec3a0-7e0f-32e6-f357-ac9311204246 -> http://example.com/profile/483ec3a0-7e0f-32e6-f357-ac9311204246/ but i get everytime an 404 error. If i try to call http://example.com/ or http://example.com/home/ i get an 500 error.
What is my problem?
You need another redirect rule for no parameters and you need to add some conditions to your internal forwarding rules so that /index.php doesn't get matched:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# external redirect from /view.php?id=1 to /view/id/1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+)&uid=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/? [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1/? [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php($|\ ) [NC]
RewriteRule ^ /? [L,R=301]
# internal forward from /view/id/1 to /view.php?id=1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?page=$1&uid=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]
It seems you're hitting problem of infinite looping causing 500. It is due to the reason that last 2 routing rules aren't skipping files and directories.
Insert this rule just above # internal forward line:
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]