Pretty url runs even with duplicate url htaccess - .htaccess

I have dynamic website and I made product name (cafeteria-table) to show when the page runs like below :
https://example.com/subcategory/cafeteria-table
Now if I edit characters in this product name (cafeteria-table) like i mentioned below it should show 404 error since it's duplicate pretty url :
https://example.com/subcategory/cafeteria
the page shouldn't run but still i can see page with header and footer with blank page and this is affecting seo.
This is my Htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
RewriteEngine on
RewriteRule ^index.php$ index.php
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
Redirect 301 /subcategory/cafe%20chairs https://example.com/subcategory/cafe-chairs
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^([^\.]+)$ $1.php [R,L]
#RewriteRule ^category/chairs$ category/index.php
RewriteRule ^category/.*$ category/index.php
RewriteRule ^subcategory/.*$ subcategory/index.php
RewriteRule ^products/.*$ products/index.php
RewriteRule ^products/.*/.*$ products/index.php
</IfModule>
Any help would be appreciated.

Related

URL redirect issue

I have a problem with redirecting single webpages within my website.
I am trying to redirect https://job-center.hu/munkaero_kozvetites/ to https://job-center.hu/munkaero-kozvetites/ and I am using the following htaccess file to do this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?q=/$1 [QSA]
</IfModule>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.allasajanlat.job-center.hu [NC]
RewriteRule ^(.*)$ https://allasajanlat.job-center.hu/$1 [L,R=301]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.job-center.hu [NC]
RewriteRule ^(.*)$ https://job-center.hu/$1 [L,R=301]
Options -Indexes
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Redirect 301 /munkaero_kozvetites/ https://job-center.hu/munkaero-kozvetites/
#SetEnv skip-cache
The result is a strange URL and I am not sure if this is OK.
Would this be considered as duplicate content by Google or this is OK as it is.
Thanks for your help in advance.
For your question about google, Redirect 301 is a permanently redirect, which means google will consider both sites the same content.

Exclude Subfolders from Rewrite rule htaccess

I have a blog page on my website and .htaccess is as below to convert SEO Friendly URL
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
So, my URL becomes http://example.com/title-of-blog and it is working pretty fine and awesome but my client reported today that admin section is not working properly and i checked and found that URL http://example.com/admin is getting converted to http://example.com/admin?prmn=admin because of above rule.
I googled how to exclude admin folder from Rewrite then i got below
RewriteRule ^admin($|/) - [L]
When i use this then when i type http://example.com/admin then m getting error page that i defined in htaccess.
Please help. My Full Htaccess is as below
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^admin($|/) - [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# remove .php from URL
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
# restrict .php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^\ ]+\.php($|\ )
RewriteRule \.php$ / [F,L]
# remove .html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)\.html$ /$1 [L,R=301]
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
ErrorDocument 404 /error-page
ErrorDocument 403 /error-page
ErrorDocument 500 /error-page
I suppose there is an other rule that does something with /admin, but because you are using that second rule it will never reach that rule. Use a condition to exclude anything starting with admin instead. Also please note that the rule would rewrite it to /blogdetail?prmn=admin, so somewhere something is rewritten more.
RewriteCond %{REQUEST_URI} !^/(admin|blogdetail)
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]

How to hide page name and extention from url using .htaccess

I want to hide all my page names and extension from url,
htt://www.domain.com/innerpage.php
to
http://www.domain.com/
and
http://www.domain.com/subfolder/innerpage.php
to
http://www.domain.com/subfolder/
and
http://www.domain.com/subfolder/subfolder/innerpage.php
to
http://www.domain.com/subfolder/subfolder/
I used like
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ http://www.domain.com/$1/ [R=301,L]
RewriteRule ^(.*)$ http://www.domain.com/subfolder/$1/ [R=301,L]
RewriteRule ^(.*)$ http://www.domain.com/subfolder/subfolder/$1/ [R=301,L]
RewriteRule ^(.*)/$ $1.php [L]
its not work
I think this will work for you
DirectoryIndex innerpage.php index.php index.html index.htm
Put this as first line of your .htaccess. This directive will look for innerpage.php if no page has been specified for a directory. If you want to hide all pages in your site URL's then it's not a good idea IMO.
Give this set of directives a try:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/?$ /innerpage.php
RewriteRule ^([a-z0-9]+)/?$ /$1/innerpage.php
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ /$1/$2/innerpage.php
RewriteRule ^innerpage.php$ / [R]
RewriteRule ^([a-z0-9]+)/innerpage.php$ /$1 [R]
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/innerpage.php$ /$1/$2 [R]
And be surprise what will happened...

dot is not working in htaccess as defined in htaccess rules

I don't have much knowledge in .htaccess and I am struggling with regex concept in .htaccess.
I want same url concept as on facebook for user profile but dash(-), underscore(_), dot(.) this I want in url also currently my url rule is as follow:
RewriteRule ^([a-z,\_,A-Z,\_,\-,0-9.][!pagenotfound|home|abuse/*|user/*|start/*|login/*|account/*|message/*|find/*|cms/*|accountactivation/*|register/*]*)/?$ memberspersonalinfo.php?members=$1 [QSA]
This pattern have some error
but when in my browser domain.com/username is comming it's working fine but when url will be domain.com/test-test or test_test or test.test it redirects to `PAGE NOT FOUND PAGE
and in my .htaccess rule defined to follow that rule like abuse/* have dynamic id wherever I have used star (*) they are referencing dynamic value. When I will do rule like
RewriteRule ^([a-z,\_,A-Z,\_,\-,0-9.]*)/?$ memberspersonalinfo.php?members=$1 [QSA]
It's working fine but when I moveto home page then it calls memberspersonalinfo.php page it self.
I am trying to explain my Question again with htaccess script
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
DirectoryIndex index.html index.php
ErrorDocument 404 /pagenotfound
ErrorDocument 403 /pagenotfound
ErrorDocument 401 /slapme/pagenotfound
ErrorDocument 500 /pagenotfound
#index
RewriteRule ^index.html$ index.php [L]
RewriteRule ^index$ index.php [L]
RewriteRule ^home$ index.php [L]
#nopage
RewriteRule ^pagenotfound$ nopage.php [L]
#Regitration
RewriteRule ^register/createaccount$ userregistration.php [L]
#Regitration Confirmation
RewriteRule ^register/accountconfirmation$ registrationconfirm.php [L]
#Activation Regitration
RewriteRule ^accountactivation/([a-z,\_,A-Z,\_,\-,0-9]*)/([a-z,\_,A-Z,=,\_,\-,0-9]*)$ registrationactivation.php?UsercontactID=$1&AccountId=$2 [L]
#after login
RewriteRule ^user/main$ after_login.php [L]
#Payment Detail
RewriteRule ^user/myaccount$ useraccount.php [L]
#Logout
RewriteRule ^user/logout$ logoutuser.php [L]
#creategroup
RewriteRule ^start/creategroup$ http://domain.com/start/creategroup [L,R=301]
#Forgot Password
RewriteRule ^user/forgotpassword$ http://domain.com/user/forgotpassword [L,R=301]
#Login
RewriteRule ^login/userlogin$ http://domain.com/login/userlogin [L,R=301]
#Remove account
RewriteRule ^account/remove$ removeuseraccount.php [L]
#Send an email page
RewriteRule ^message/?$ contacttouser.php [L,QSA]
#Report any site user page
RewriteRule ^abuse/([0-9]*)/$ reportsiteuser.php?reportUserID=$1 [L,QSA]
#CMS FIND FRIENDS PAGE
RewriteRule ^find/friend$ http://domain.com/find/friend [L,R=301]
#CMS TERMS OF USE PAGE
RewriteRule ^cms/howitworks$ howitworks.php [L]
#CMS CREATE OWN SLAP PAGE
RewriteRule ^cms/createownslap$ createownslap.php [L]
#CMS BRAND OR PRODUCT PAGE
RewriteRule ^cms/brandorproduct$ brandorproduct.php [L]
#CMS APPS AND FEATURES PAGE
RewriteRule ^cms/appsandfeatures$ appsandfeatures.php [L]
this my full htaccess code everthing is working fine all rules are working but when i add
#group personal profile page page
RewriteCond %{REQUEST_URI} !/abuse(.*)
RewriteCond %{REQUEST_URI} !/user(.*)
RewriteCond %{REQUEST_URI} !/start(.*)
RewriteCond %{REQUEST_URI} !/login(.*)
RewriteCond %{REQUEST_URI} !/account(.*)
RewriteCond %{REQUEST_URI} !/message(.*)
RewriteCond %{REQUEST_URI} !/find(.*)
RewriteCond %{REQUEST_URI} !/cms(.*)
RewriteCond %{REQUEST_URI} !/accountactivation(.*)
RewriteCond %{REQUEST_URI} !/register(.*)
RewriteCond %{REQUEST_URI} !/social(.*)
RewriteCond %{REQUEST_URI} !/images(.*)
RewriteCond %{REQUEST_URI} !/css(.*)
RewriteCond %{REQUEST_URI} !/js(.*)
RewriteCond %{REQUEST_URI} !/userimages(.*)
RewriteRule ^([a-z,\_,A-Z,\_,\-,0-9.]+)/?$ memberspersonalinfo.php?members=$1 [QSA,L]
it always loads memberspersonalinfo.php

.htaccess make friendly url

I have a problem with making friendly URL. I need to convert url from http://blabla.eu/stats_details?date=01-2012 to http://blabla.eu/stats_details/01-2012. Other Rewrite rules are working properly beside the last one. What is the problem?
Here is code of .htaccess:
AddDefaultCharset utf-8
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^admin/users/$ /admin/users/view.php [L]
RewriteRule ^admin/loans/$ /admin/loans/view.php [L]
RewriteRule ^stats_details/(.*)$ stats_details.php?date=$1 [L,QSA]
</IfModule>
I think this must to work, try to paste
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Resources