Renaming inner page urls to seo friendly urls using .htaccess - .htaccess

I want to rename the following URLs to SEO friendly URL.
Change the following URL : http://www.peacockgirls.com/index.php?page=1 into http://www.peacockgirls.com
Change the following URL : http://www.peacockgirls.com/index.php?page=2 into http://www.peacockgirls.com/greece-escort
Change the following URL : http://www.peacockgirls.com/index.php?page=3 into http://www.peacockgirls.com/athens-escort
Change the following URL : http://www.peacockgirls.com/index.php?page=4 into http://www.peacockgirls.com/bookings
Change the following URL : http://www.peacockgirls.com/index.php?page=5 into http://www.peacockgirls.com/jobs
Change the following URL : http://www.peacockgirls.com/index.php?page=6 into http://www.peacockgirls.com/contact-us
Change the following URL : http://www.peacockgirls.com/index.php?page=24 into http://www.peacockgirls.com/articles
Change the following URL : http://www.peacockgirls.com/index.php?page=7 into http://www.peacockgirls.com/links
Change the following URL : http://www.peacockgirls.com/index.php?profile=22 into http://www.peacockgirls.com/profile/aleena
Change the following URL : http://www.peacockgirls.com/index.php?profile=40 into http://www.peacockgirls.com/profile/fabiana
Change the following URL : http://www.peacockgirls.com/index.php?profile=48 into http://www.peacockgirls.com/profile/sabrina
Change the following URL : http://www.peacockgirls.com/index.php?profile=69 into http://www.peacockgirls.com/profile/suzanna
Change the following URL : http://www.peacockgirls.com/index.php?profile=63 into http://www.peacockgirls.com/profile/anna
Change the following URL : http://www.peacockgirls.com/index.php?profile=70 into http://www.peacockgirls.com/profile/sam
Change the following URL : http://www.peacockgirls.com/index.php?profile=61 into http://www.peacockgirls.com/profile/Larissa&Samantha
Change the following URL : http://www.peacockgirls.com/index.php?profile=54 into http://www.peacockgirls.com/profile/McKenzie
Change the following URL : http://www.peacockgirls.com/index.php?profile=29 into http://www.peacockgirls.com/profile/valery
If you show me 4 or 5 URLs renaming techniques using .htaccess, I shall do remaining URLs. I was given this task, but can't do it.

With that kind of tasks I would go for RewriteMap.
You could use two separate map text files (for better file management): one for profiles and one for pages (any new file for other type of rewrites).
Your .htaccess could be setup that way:
RewriteMap userid txt:/etc/apache2/useridmap.txt
RewriteRule ^/index.php?page=(.+) /profile/${userid:$1} [L,R=301]
Map text file format is as follows:
# Comment line
MatchingKey SubstValue
MatchingKey SubstValue # comment
In your case, profiles text file could look as follows:
22 aleena
40 fabiana
# more mappings
For page redirects you can use following approach (map file will be different as well as RewriteRule expressions)
Before any work, I would recommend going through RewriteMap documentation first so you understands the tool i.e. its configuration and usage.
I hope that will be good direction for your task.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule %{REQUEST_FILENAME} !-d
RewriteBase /
RewriteRule ^/greece-escort/?$ /index.php?page=2 [NC,L]
RewriteRule ^/athens-escort/?$ /index.php?page=3 [NC,L]
RewriteRule ^/bookings/?$ /index.php?page=4 [NC,L]
RewriteRule ^/jobs/?$ /index.php?page=5 [NC,L]
RewriteRule ^/contact-us/?$ /index.php?page=6 [NC,L]
RewriteRule ^/articles/?$ /index.php?page=24 [NC,L]
RewriteRule ^/links/?$ /index.php?page=7 [NC,L]
RewriteRule ^/profile/aleena/?$ /index.php?profile=22 [NC,L]
RewriteRule ^/profile/fabiana/?$ /index.php?profile=40 [NC,L]
RewriteRule ^/profile/sabrina/?$ /index.php?profile=48 [NC,L]
RewriteRule ^/profile/suzanna/?$ /index.php?profile=69 [NC,L]
RewriteRule ^/profile/anna/?$ /index.php?profile=63 [NC,L]
RewriteRule ^/profile/sam/?$ /index.php?profile=70 [NC,L]
RewriteRule ^/profile/Larissa&Samantha/?$ /index.php?profile=61 [NC,L]
RewriteRule ^/profile/McKenzie/?$ /index.php?profile=54 [NC,L]
RewriteRule ^/profile/valery/?$ /index.php?profile=29 [NC,L]
</IfModule>
.htaccess

Related

How can I redirect url with .htaccess like instagram?

If the link does not have any value, redirect to index.php.
Example;
www.mydomain.com/ --> index.php
If the link is www.example.com/post/value, redirect to post.php.
Example;
www.mydomain.com/post/cDfS58Q --> post.php
If the link only consists of value, redirect to profile.php.
Example;
www.mydomain.com/jhon.34 --> profile.php
My test:
RewriteRule ^post/([0-9a-zA-Z-_/.]+)$ post.php?$1 [QSA,L]
RewriteRule ^([0-9a-zA-Z-_/.]+)$ profile.php?$1 [QSA,L]
but they all go to post.php.
Set the rewrite rules for each scenario except for the link that does not have any value. The default file that opens when visiting a website is the index file so you don't need to explicitly set it.
Go from longest URI to smallest because the condition of the smaller URI usually satisfies the conditions for the bigger URI.
Try somethig like this:
# Mod Rewrite setup
Options +FollowSymlinks
RewriteEngine on
AddDefaultCharset UTF-8
# First enter the one with the longest URI
RewriteCond %{REQUEST_URI} ^/?post/([0-9a-zA-Z-_/.]+)/?$
RewriteRule ^(.*)$ /post.php?data=%1 [NC,L]
# Then the one with only value
RewriteCond %{REQUEST_URI} ^/?([0-9a-zA-Z-_/.]+)/?$
RewriteRule ^(.*)$ /profile.php?data=%1 [NC,L]
I did it in a different way ;
htaccess
RewriteRule ^p/(.*)$ post.php?$1 [QSA,L]
RewriteRule ^([0-9a-zA-Z]+)$ index.php?$1 [QSA]
RewriteRule ^([0-9a-zA-Z]+)/$ index.php?$1 [QSA]
index.php
<?php
if (!empty($_SERVER['QUERY_STRING'])) {
//Profile.php will be included here.
echo "You are in profile now.";
}else {
//Homepage.php will be included here.
echo "You are in profile now.";
}
?>
Url : www.localhost.com/adsasd
Output : You are in profile now.
Url : www.localhost.com/
Output : You are in homepage now.

how to replace "?" and "=" sign with "/" in URL - PHP htaccess

i am working on project, which is running XAMPP localhost and PHP MYSQLI,
my question : how i replace "?","=" signs with "/" slash. ?
like, my url is "archive?date=2017-06-02&p=4"
and i want to force it "archive/2017-08-02/4"
i found many codes on stackoverflow and some other sites, but that are not working for me.
if codes are working then, CSS files and GET method doesn't work on my project.
complete code of .htaccess is given below.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^=]*)=([^=]*)=(.*) /$1/$2/$3 [N]
RewriteRule ^([^=]*)=([^=]*)$ $1/$2 [L]
RewriteRule ^home index.php [NC,L]
RewriteRule ^archive archive.php [NC,L]
RewriteRule ^about about.php [NC,L]
RewriteRule ^article article.php [NC,L]
RewriteRule ^news news.php [NC,L]
RewriteRule ^video videos.php [NC,L]
RewriteRule ^video?vid=([0-9]+) videos.php?q=$1 [NC,L]
RewriteRule ^article?num=([0-9]+) article.php?num=$1 [NC,L]
RewriteRule ^editorial?num=([0-9]+) editorial.php?num=$1 [NC,L]
RewriteRule ^news?news=([0-9]+) news.php?news=$1 [NC,L]
You cannot check against the query string in a rewrite rule. You need rewrite conditions for that:
RewriteCond %{QUERY_STRING} date=([^&]+)&p=(.+)
RewriteRule ^archive/? /archive/%1/%2?
Demo here: http://htaccess.mwl.be?share=81e85c09-d505-5206-ab14-6c5059107808
If you want to actually redirect just add [R=301,L] to the end of the RewriteRule.
However, looking at the above I suspect you have your script sitting listening at /archive/index.php?data=foo&p=bar but want URLs to be like /archive/date/p, ie pretty.
This is actually a very common misconception about how htaccess URL rewrites work when you first get into them.
RewriteRules will mask or redirect URLs for you but they cannot change the underlying location a script is located at and thus the address used to pass it information.
In other words - you can mask /archive/index.php?data=foo&p=bar as /archive/date/p so that requests made to /archive/date/p resolve to /archive/index.php?data=foo&p=bar, but you cannot make it so that if you enter /archive/index.php?data=foo&p=bar as URL you have the URL change to /archive/date/p while still serving content from /archive/date/p. It has to be either or.
If this all sounds about right my advice would be as follows:
First, put your code into a different file, say /archive/script.php.
Next add the following to your htaccess:
RewriteCond %{QUERY_STRING} date=([^&]+)&p=(.+)
RewriteRule ^archive/? /archive/%1/%2? [R=301,L]
RewriteRule ^archive/([^/]+)/([^/]+) /archive/script.php?date=$1&p=$2
Note that the first two lines are the same as before, but now there is a new line that looks for the masked URL format of /archive/date/p and sends it off to the actual script, which is handled by the new RewriteRule.
The behaviour of the new rule is demoed here: http://htaccess.mwl.be?share=06751667-f16f-5c13-91eb-dd5cffdc6db3
Hope this makes sense / helps.

how to Rewrite Single Page url in .htaccess

I need to rewrite only 1 specific URL
from
http://www.domainname.com/index.php?route=payment/axis/callback
to
http://www.domainname.com/payment/axis/callback
I tried these two from stack overflow, I don't know why its not working
1st one :
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?route=payment/axis/callback [NC,L]
2nd one :
RewriteRule ^index.php?route=payment/axis/callback payment/axis/callback [L]
Try this:
4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
See the full page here.
Hope it helps!
I wouldn't use .htaccess with RewriteRule, since there are often problems with it. A simple workaround (with PHP redirect):
<?php
if($_GET['route'] == 'payment/axis/callback') {
header("Location: http://www.domainname.com/payment/axis/callback");
}
?>
You can either use h0ch5tr4355's workaround or you can try this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^route=payment/axis/callback$
RewriteCond %{SCRIPT_FILENAME} index.php
RewriteRule (.*) /payment/axis/callback [NC,QSD]
If you instead of a rewrite would like it to redirect to the new url you can add R=301 to the flags of the RewriteRule.

.htaccess 2 Dyanamic Rewrite URL

I have a dynamic url at
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%|tag|&limit=20
where the '|tag|' and '20' part change depending on the tag. This is Movable Type blogging platform which is written in perl. The '|tag|' part is a place holder for the tag. For example, if the tag was 'there' the url would be
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%there&limit=20
and not
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%|tag|&limit=20
I was wondering how to rewrite that in htaccess because everything I try doesn't work. I want it to be
http://www.technicae.net/tag/|tag|
instead of
http://www.technicae.net/cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%|tag|&limit=20
can you please help me?
note
The URLS are not functional.
This is what you're searching for :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^tag/([^/]+)$ cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%$1 [L]
RewriteRule ^tag/([^/]+)/limit/([^/]+)$ cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%$1&limit=$2 [L]
This will allow thos kind of url :
www.domain.com/tag/<myTag>
www.domain.com/tag/<myTag>/limit/<myLimit>
But not :
www.domain.com/limit/<myLimit>
Assuming you are using Apache, make sure you have mod_rewrite enabled.
The .htaccess you should use (this may need tweaked) is:
RewriteEngine On
RewriteRule ^tag/([^\.]+)$ cgi-bin/type/mt-search.cgi?IncludeBlogs=2&tag=2%$1&limit=20 [NC,L]

htaccess : rewrite urls

please help to rewrite Urls from
http://www.site.com/index.php?cat=catname
and
http://www.site.com/index.php?id=productname
to be like this
http://www.site.com/catname
and
http://www.site.com/productname
i think it will require php check if the page is cat work with it as cat
or its product work with it as product
in .htaccess file:
RewriteEngine On
RewriteRule ^([0-9a-z\-\_]+)?$ /index.php?id=$1 [L,QSA,NC]
category/product check must be done in index.php...
Or you can add extra slug
RewriteRule ^(category)/([0-9a-z\-\_]+)?$ /index.php?category=$1 [L,QSA,NC]
RewriteRule ^(product)/([0-9a-z\-\_]+)?$ /index.php?product=$1 [L,QSA,NC]
but url will look like http://site.com/category/catname
http://www.site.com/catname and http://www.site.com/productname
The problem with that scheme is that you can't tell whether it's a catalog name or a product name by the URL. As a result, you'll probably want something like this:
http://www.site.com/Catalog/catname and http://www.site.com/Product/productname
Which can then be implemented in a .htaccess file with the following rules:
RewriteEngine On
RewriteRule ^Catalog/(.+)$ /index.php?cat=$1 [L]
RewriteRule ^Product/(.+)$ /index.php?id=$1 [L]

Resources