shorting URL with HTACCESS - php

htaccess in this page
www.mysite.it/LABS/page.php?id=value
to
www.mysite.it/LABS/value
i try this but not work
RewriteCond %{REQUEST_URI} LABS/page\.php?name=$1 [NC]
RewriteRule ^([^/]*)$ /page\.php?id=$1 [L]
Solutions?

I hope this works for you
RewriteEngine On
RewriteRule ^([^/]*)$ /LABS/page.php?id=$1 [L]
I usually use a mod_rewrite generator
Source

Try this :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /LABS/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ page.php?/$1 [QSA,L]
</IfModule>

Related

.htaccess rewrite options for index.php and GET variables

I have a problem with the Rewrite options and I can't find the right answers on the internet so I hope this community can help me.
I am working local on a web project and use XAMPP as my local webserver.
I made a VirtulHost (basic.localhost) and now there is my problem with the mod_rewrite options.
When there is an url: basic.localhost/index.php/var1=option1&var2=option2&var3=option3&var4=option4
I want to rewrite the url to this: basic.localhost/option/option2/option3/option4
The var1 to var4 variables are used as GET variables to select content from an database.
This is my .htaccess now:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
And all Rewrite Rules that I tried does not work...
I found an answer for the problem with the variables:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2&var3=$3&var4=$4 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2&var3=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2 [L,QSA]
RewriteRule ^([^/]+)$ index.php?var1=$1 [L,QSA]
</IfModule>
Now there is only the Problem with the index.php.
I finally got a solution for this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2&var3=$3&var4=$4 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2&var3=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2 [L,QSA]
RewriteRule ^([^/]+)$ index.php?var1=$1 [L,QSA]
</IfModule>

Want to generate redirct rule for htaccess

I am having trouble to generate redirection rule I tried so many possible ways but those are not working.
Here are the details:
1) Current link: https://app.abcd.com (Showing in url)
2) Redirect to: https://app.abcd.com/index.php/login
3) Should be renamed as : https://app.abcd.com/login
I have tried :
RewriteEngine on
RewriteRule (.*) http://https://app.abcd.com/index.php/login/$1 [R=301,L]
Didn't work!
Any help!
You can use this :
RewriteEngine on
RewriteRule ^$ /index.php/login [L,R]
This will redirect your homepage / to /index.php/login
You can also accomplish this using RedirectMatch
RedirectMatch 301 ^/$ /index.php/login/
Try it.
Options +FollowSymlinks
Options -Indexes
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
RewriteEngine on
RewriteBase /example/
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) index.php/$1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)/([^?]*) index.php?_cmd_=$1/$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_cmd_=$1 [L,QSA]
.htaccess for codeigniter:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
And in config.php:
change:
$config['index_page'] = "index.php";
to:
$config['index_page'] = "";
HTACCESS
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Open config.php and do following replaces
$config['index_page'] = "index.php"
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
IndexIgnore *
Try to add this in your .htacces file:
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]

.htaccess rule appending index.php instead of URI

My .htaccess looks like this..
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [R,L]
</IfModule>
I want to be able to redirect an URL that looks like this..
https://sub.domain.com/ZTHF76
to...
https://www.domain.com/members/invite/ZTHF76
But instead I am getting
https://www.domain.com/members/invite/index.php
I need to keep the first rule to remove index.php from the URI of the rest of the application.
Any help with this greatly appreciated.
You should reorder your rules and keep redirect rule before rewrite one:
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

URL Rewriting for sub-folder

I need a URL like this:
http://domain.com/subfolder/file.php?src=quick-brown-fox&m=1&size=320x480
.. changed to:
http://domain.com/subfolder/file/quick-brown-fox/320x480
I updated the htaccess with:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/subfolder/([^\.]+)$ $1.php [NC,L]
but I'm getting a 404. What am I doing wrong?
You could do this in subfolder/.htaccess
Options -MultiViews
RewriteEngine On
RewriteBase /subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?(.*)$ $1.php [NC,L]
Then capture the URI in php.
You can have this rule in /subfolder/.htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /subfolder/
RewriteRule ^(file)/([^/]+)/([^/]+)/?$ $1.php?src=$2&m=1&size=$3 [QSA,NC,L]

.htaccess Rewrite 505 Error Loop

I am trying to rewrite:
mydomain.com/category.php?id=cat
to
mydomain.com/cat
I have used the following .htaccess code but it keeps showing a 505 error:
RewriteEngine On
RewriteRule ^([^/]*)$ /category.php?id=$1 [L]
I read on another page that it is because the page keeps looping, but I can't work out how I can fix the code.
Keep your rule like this:
RewriteEngine On
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /category.php?id=$1 [L,QSA]
Try this.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)/ category.php?id=$1 [L]
</IfModule>
You need to add RewriteCond to avoice rewrite for category.php
RewriteEngine On
RewriteCond %{REQUEUST_URI} !^ /category.php/(.*)
RewriteRule ^(\w+)/ category.php?id=$1 [L]
Ok this should work:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/category.php
RewriteRule ^(.*)$ category.php?id=$1 [R=301,L]
Demo: http://ht6.valhook.com/cat

Categories