Using htaccess how can instead of the following to have something like
http://domain.com/verify
or
http://domain.com/verify?user=_FIRST-VARIABLE_&verification_code=_SECOND-VARIABLE_
Here is the original
http://domain.com/account/index.php?user=_FIRST-VARIABLE_&verification_code=_SECOND-VARIABLE_
My current htaccess is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^login$ account/index.php [NC]
RewriteRule ^register$ account/index.php?register [NC]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Try this RewriteRule with the regex pattern
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^varify/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$/account/index.php?foo=$1&bar=$2 [NC,QSA,L]
change the variables foo and bar with your variables.
All requests to example.com/varify/var1/var2 will be redirected to example.com/account/index.php?foo=$1&bar=$2
Related
I am working on a project where I decided to get rid of the .php extension from the URL of my app. I am successful using the htaccess code given below. But the problem is, the page still loads using .php extension if typed manually or loaded from the history.
My current .htaccess code.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I want it to always load with www.example.com/dashboard except www.example.com/dashboard.php even if dashboard.php is manually typed.
UPDATED .htaccess code
RewriteEngine On
RewriteBase /dateapp/
RewriteRule ^([^\.]+).php$ $1 [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,END]
You can add redirect as first rule.
RewriteEngine On
RewriteRule ^([^\.]+).php$ /$1 [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,END]
You have to use END flag instead of L otherwise the redirects will end in infinite loop. This will work if the .htaccess is in your webroot folder.
In case you have .htaccess in 'folder' subfolder you will have to add RewriteBase
RewriteEngine On
RewriteBase /folder/
RewriteRule ^([^\.]+).php$ $1 [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,END]
You may use this code in dateapp/.htaccess:
RewriteEngine On
RewriteBase /dateapp/
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
How do I create rewrite rule to get pretty link using .htaccess. for example I have a link like this:
http://localhost/piratefiles/view.php?idp=2&cat=Animation&pst=In-this-Corner-of-the-World-(Kono-Sekai-no-Katasumi-ni)/
I want to make my url like this, I do'nt want ( or ) or : etc in my link.
http://localhost/piratefiles/view/2/in-this-corner-of-the-world-kono-sekai-no-katsumi-ni
or just
http://localhost/piratefiles/view/2/
my code
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} "^([^/]*?)(?:/|%20)+([^/]+?(?:/|%20)+.*)$"
RewriteRule ^ %{REQUEST_URI}?%1-%2 [N,NE]
RewriteCond %{QUERY_STRING} "^([^/]*?)(?:/|%20)+([^/]+?)/?$"
RewriteRule ^ %{REQUEST_URI}?%1-%2/ [L,R=302,NE]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/$ index.php [L]
#Your section
RewriteRule ^view/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ view.php?idp=$1&cat=$2&pst=$3 [NC,L]
ErrorDocument 404 http://www.akshadainfosystem.com/
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Put this code in your .htaccess file and clear all cookie
I currently have very little Apache experience, and am having difficulties with my .htaccess file. My question is this: how can I rename these files, listed below, properly? I believe my syntax is accurate, according to http://www.htaccesscheck.com, but when accessing these pages, either A: the page won't load due to a redirect loop, or B: the page won't load, but will redirect to the wrong page. Here is my current .htaccess file for this directory:
RewriteEngine On
RewriteBase /photos/
RewriteRule ^(.*)-(.*)$ archives.php?month=$1&year=$2 [L]
RewriteRule ^(.*)$ catpost.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]
Any help is much appreciated.
Try code below:
RewriteEngine on
RewriteBase /photos/
RewriteRule ^([0-9]{1,2})-([0-9]{4})$ archives.php?month=$1&year=$2 [L]
RewriteRule ^([0-9]+)$ catpost.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]
This rules will check, if:
request like yourdomain/11-1111, then return archives.php
request like yourdomain/111, then return catpost.php (you can type
any number)
else will return viewpost
You have some errors in your current .htaccess, because your second rule get result of first rule.
By the way, you can use http://htaccess.madewithlove.be/ to check step by step what is posted to your rewrite rules.
be sure to write a valid pattern
try this
RewriteEngine On
RewriteBase /photos/
RewriteRule ^(.*?)-(.*?)$ archives.php?month=$1&year=$2 [L]
RewriteRule ^(.*?)$ catpost.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*?)$ viewpost.php?id=$1 [QSA,L]
Every signed up member has an userprofile. The URL looks like: http://domain.com/content/profile/profile.php?username=USERNAMEOFTHEUSER
How do I rewrite it so it shows the URL as: http://domain.com/USERNAMEOFTHEUSER ?
I've tried:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^/]*)\.html$ content/profile/$1 [L,QSA]
But it aint working and I have no htaccess knowledge.
EDIT #1
Also, my map structure looks like this:
content/example1/example_file1.php
content/example2/example_file2.php
content/example3/example_file3.php
How do I hide the content/examples/ maps? So that: domain.com/content/example2/example_file2.php
turns into domain.com/example_file2 ?
Thanks!
This should work:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /content/profile/profile\.php\?username=(.*)\ HTTP
RewriteRule ^ /%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /content/profile/profile.php?username=$1 [L]
I am new one, I learn .htaccess. I want to customize my URL
from
index.php?page=mobile
to
index/page/mobile
I used this code but it doesn't work:
RewriteEngine on
RewriteRule ^index/([0-9]+)/?$ index.php?page=$1 [NC,L] # Handle product requests
and
RewriteEngine on
RewriteRule ^index/([^/.]+)/?$ index.php?page=$1 [L]
This rule should work:
RewriteEngine on
RewriteBase /cashearn/
RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ index/page/%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index/page/([^/]+)/?$ index.php?page=$1 [L,QSA,NC]
This will let you have URL as http://domain.com/index/page/mobile on your page.
Try that code:
RewriteEngine on
RewriteBase /
RewriteRule ^index/page/([^/.]+)/?$ index.php?page=$1 [L,QSA,NC]
This should work - not tested though
RewriteRule ^index/page/([^/.]+)$ index.php?page=$1 [L,QSA,NC]