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
Related
I´ve made some RewriteRules in my .htaccess and they all work if I call my Website from the Domain/URL of my server.
Now I wanted to point an external Domain to my subfolder on my server where my Website is located, but all RewriteRules aren´t working anymore. When I call the php-files everything is alright, but when I call my "beautiful" links, I wanted to create, then only error 404 is shown.
This is currently my .htaccess file:
ErrorDocument 401 /401.php
ErrorDocument 404 /404.php
RewriteEngine On
#redirect www request to the base domain
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#ignore existing files and directories
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
# Check if query string exists
RewriteCond %{QUERY_STRING} ^$
# Check that the request is not for an existing file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^spielplan$ spielplan.php [NC,L]
RewriteRule ^rangliste$ rangliste.php [NC,L]
RewriteRule ^alletipps$ allbets.php [NC,L]
RewriteRule ^benutzerseite$ userpage.php [NC,L]
RewriteRule ^einstellungen$ usersettings.php [NC,L]
RewriteRule ^spiel/([0-9]+)/?$ spiel.php?id=$1 [NC,L]
RewriteRule ^user/([A-Za-z0-9-]+)/?$ user.php?name=$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ $1.php [NC,L]
I found a solution.
Because I tried to map my domain to a subfolder, this subfolder needs to work like an DocumentRoot and not like a subfolder.
So I needed to add:
RewriteBase /
in my .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]
I have a problem with subdomains I used to translate my website. With the 4 first lines of code, I've no problem, the sub var is passed fine (http://en.mywebsite.com/ gives http://mywebsite.com?sub=en). The 5th line is used to manage ads, once I click on the link like http://en.mywebsite.com/blue-chair-Vha6J.html the page isn't loaded and I stay on the home page. It should gives me something like http://mywebsite.com?sub=en&menu=ad&ad=Vha6J. Instead of this, it gives me http://mywebsite.com?sub=en.
RewriteBase /
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} ^([a-z]+)\.mywebsite\.com$ [NC]
RewriteRule ^(.*) ?sub=%1 [NC,L]
RewriteRule ^([-a-z0-9]+)-([A-Za-z0-9]+)\.html$ ?sub=%1&menu=ad&ad=$2 [L]
[EDIT 1]
Ok, here is a bigger htaccess extract, included the modifications I made with the first answer, and I still have problems :
RewriteBase /
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} !&menu=.*
RewriteCond %{HTTP_HOST} ^([a-z]+)\.mywebsite\.com$ [NC]
RewriteRule ?sub=%1 [NC,L]
RewriteCond %{HTTP_HOST} ^([a-z]+)\.mywebsite\.com$ [NC]
RewriteRule ^cart$ ?sub=%1&menu=cart [L]
RewriteRule ^login$ ?sub=%1&menu=login [L]
########### AD
RewriteRule ^([-a-z0-9]+)-([A-Za-z0-9]+)\.html$ ?sub=%1&menu=ad&ad=$2 [L]
RewriteRule ^([-a-z0-9]+)-([A-Za-z0-9]+)\.html\/([A-Za-z0-9]+)$ ?sub=%1&menu=ad&ad=$2&secret=$3 [L]
########### ADS
RewriteRule ^all\/([-A-Za-z0-9]+)$ ?sub=%1&menu=ads§ion_name=$1 [L]
RewriteRule ^all\/([-A-Za-z0-9]+)\/([-A-Za-z0-9]+)$ ?sub=%1&menu=ads§ion_name=$1&category_name=$2 [L]
RewriteRule ^all\/([-A-Za-z0-9]+)\/([-A-Za-z0-9]+)\/([-A-Za-z0-9]+)$ ?sub=%1&menu=ads§ion_name=$1&category_name=$2&subCategory_name=$3 [L]
########### SHOPS
RewriteRule ^shops$ ?sub=%1&menu=shops [L]
########### SHOP
RewriteRule ^([-a-z0-9]+)$ ?sub=%1&menu=shop&shop=$1 [L]
RewriteRule ^([-a-z0-9]+)\/([-a-z0-9]+)$ ?sub=%1&menu=shop&shop=$1&category_name=$2 [L]
When I'm on the home page https://en.mywebsite.com/, the sub var "en" is passed fine. If I go on https://en.mywebsite.com/login for instance, the page is loaded, but the sub var "en" isn't passed.
Any idea ? Thanks.
the problem is that the url is Rewritten twice , the first time /sample-vg.html is rewritten correctly to ?sub=en&menu=ad&ad=fg, then in the second run the new url is been rewritten again to ?sub=en (L flag just stop the current run, not the entire process, take a look here)
there is also a problem with the second RewriteRule(undefined %1),
the following code should work as expected:
RewriteBase /
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} !&ad=.*
RewriteCond %{HTTP_HOST} ^([a-z]+)\.mywebsite\.com$ [NC]
RewriteRule ^(.*) ?sub=%1 [NC,L]
RewriteCond %{HTTP_HOST} ^([a-z]+)\.mywebsite\.com$ [NC]
RewriteRule ^([-a-z0-9]+)-([A-Za-z0-9]+)\.html$ ?sub=%1&menu=ad&ad=$2 [L]
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...
I have the following .htaccess config
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule \.git - [F,L]
RewriteRule ^help help.php [L]
RewriteRule ^home home.php [L]
RewriteRule ^profile profile.php [L]
RewriteRule ^index index.php [L]
RewriteRule ^users/([0-9]+) profile.php?id=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)?$ profile.php?u=$1 [L]
Now, whenever somebody visits the landing page, they get redirected using the last rule for profile.php?u=$1.
How do I change the configuration so that www.example.com and www.example.com/ are mapped to index.php and not profile.php?
Match the empty string or single slash just after the ^index rule:
RewriteRule ^help help.php [L]
RewriteRule ^home home.php [L]
RewriteRule ^profile profile.php [L]
RewriteRule ^index index.php [L]
# Match root request with optional slash
RewriteRule ^/?$ index.php [L]
I will suggest not to do it this way.
Instead, simply user this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
This will send all your requests to index.php page, from there create a router.php and pass on the requests to that page, using php.
but in case you do, just add
RewriteRule ^/?$ index.php [L]
Like Michael suggested.
Here is a simple tool to test your rules, if you wish to
Apache RewriteRule tester