edit htaccess to get inside a folder for rewrite rule - .htaccess

After some help from another question i managed to figure out about .htaccess on my website for Friendly SEO links.
My public_html folder contains those files
index.php
.htaccess
buisnessdetails.php
eventDetails.php
My htaccess so far is this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)\ (.*)$ /$1-$2 [L,R=301]
RewriteCond %{THE_REQUEST} /eventDetails\.php\?id=(.+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
</IfModule>
So when someone clicks an href which has http://sourtouki.gr/123/abc
the htaccess file goes to the
eventDetails.php file.
But now i want it to change like this
i've edited my public_html folder like this
index.php
events(folder)
2.1 eventDetails.php
buisness(folder)
3.1 buisnessdetails.php
So with these changes i want to do the following thing
Changed the href link to
http://sourtouki.gr/events/123/abc
What changes i must do to the .htaccess file so it can understand that if someone pushes the above link, to go to the eventDetails.php which is inside events folder??
And is it going to be editable so i can add also buisness folder inside that rewrite rule?

You can use something like :
RewriteEngine on
RewriteRule ^(.*)\ (.*)$ /$1-$2 [L,R=301]
RewriteCond %{THE_REQUEST} /events/eventDetails\.php\?id=(.+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /events/%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]+)/([^/]+)/?$ /events/eventDetails.php?id=$1&name=$2 [L]

Related

htaccess rewrite going to 404?

for the last hours I cant seem to figure out why my .htaccess file is redirecting to a blank url. Here is my htaccess file below.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-l
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^(.*)$ /test/user-profile/%1? [R=301,L]
I am trying to rewrite www.example/test/user-profile?id=4 ->>> www.example/test/user-profile/4
It does rewrite the url, however then the page has "The requested URL was not found on this server." the htaccess file is in public_html folder, so I am trying to select a specific user inside www.exampleurl.com/test/userslist.php which would go to www.exampleurl.com/test/user-profile.php. It all works perfectly before using htaccess. www.example/test/user-profile?id=4 ->>> www.example/test/user-profile/4 but it just wont find the url or file? im a super noob folder path below -> public_html/test/userslist.php & user-profile.php
Just cant seem to figure out what to do. Yes I do have mod-rewrite on.
With your shown samples, please try following htaccess rules file.
This assumes that you are hitting link www.example/test/user-profile?id=4 in browser which is redirecting to www.example/test/user-profile/4 and is being served by index.php with parameters user-profile=user-profile in your url and id=digits in url. You can also change them as per your need.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine On
RewriteBase /test/
RewriteCond %{THE_REQUEST} \s/(test/user-profile)\?id=(\d+)\s [NC]
RewriteRule ^ %1/%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*/)/([*/]*)/?$ test/user-profile.php?user-profile=$1&id=$2 [QSA,L]
2nd solution: In case someone is hitting url example.com/test/user-profile/7 then try following htaccess rules.
RewriteEngine On
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*/)/([^/]*)/(\d+)/?$ test/user-profile.php?user-profile=$1&id=$2 [QSA,L]

How can I hide folder name from URL using .htaccess

I have a website with the root folder 'www', but I put all php files including index.php in a sub-folder of root.
I wrote myself a .htaccess file to redirect, so if I input www.test.com, it will jump to www.test.com/folder and display the index.php.
Below it's my .htaccess which I put in the root.
RewriteEngine On
RewriteBase /
RewriteRule ^folder2 - [L]
#ignore folder2 in which I put important files, but no works for the website
RewriteCond %{REQUEST_URI} !^/folder(.*)
RewriteRule (.*) /folder/$1
Right now, I want to change the .htaccess file to reach these goals:
When I input www.test.com, jump to www.test.com/folder as usual, but display the url without folder.
All the pages in folder will display the url without folder name.
Such as
www.test.com/shop/page1 -> www.test.com/page1
I searched some of the scripts, but none of them works.
I've found this related question which answers to your problem. The snippet from the answer is (note: it's adjusted to your needs):
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+folder/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^folder/)^(.*)$ /folder/$1 [L,NC]
Reference: https://stackoverflow.com/a/18361995/3673491
You can use below code.
RewriteEngine On
RewriteBase /
RewriteRule ^/?$ /folder/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/$1 [L]
Based on your current rules. You can just make a slight adjustment.
RewriteEngine On
RewriteBase /
#ignore folder2 in which I put important files, but no works for the website
RewriteRule ^folder2/? - [L]
RewriteRule ^/?$ /folder/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/$1 [L]

reroute htaccess when index in any subfolder

I currently have the following rewrite set up in my htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/(.*)$ index.php?controller=$1&cmd=$2&params=$3 [L,QSA]
RewriteRule ^([^/]*)/([^/]*)$ index.php?controller=$1&cmd=$2 [L,QSA]
RewriteRule ^([^/]*)$ index.php?controller=$1 [L,QSA]
So for example blog just rewrites to index.php?controller=blog or blog/show/32 rewrites to index.php?controller=blog&cmd=show&params=32 etc etc.
I want to shift all my site into a subfolder called testing so need to update my htaccess to suit. Not worried about rerouting to the folder i.e. i'm not bothered about typing www.example.com and it landing at /testing/index.php, I want to type www.example.com/testing/ and it land at index.php which it does but the other rules seem to break.
If you move this .htaccess to the subfolder, together with the files, it will work just as expected. You don't need to change anything. If you have a RewriteBase directive in your .htaccess, you have to update it to reflect the new path.
Keep this rule in your root .htaccess:
RewriteEngine On
RewriteRule ^((?!testing/).*)$ testing/$1 [L,NC]
Keep this rule in your /testing/.htaccess`:
RewriteEngine On
RewriteBase /testing/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/(.+)$ index.php?controller=$1&cmd=$2&params=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?controller=$1&cmd=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?controller=$1 [L,QSA]

UrL Rewrite using code with my domain

URL : http://domainname.com/index.php?p=top-games
I need to rewrite this as http://domainname.com/top-games
How I do this using htaccess file? Please can any one give me the htaccess code.
Thanks
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]
</IfModule
Create .htaccess file in your root folder and paste code
You're probably looking for redirect in reverse direction.
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /index.php?q=$1 [L,QSA]

How can I do this mod_rewrite?

I want to redirect all http://localhost/webportal/organizations/32 requests to http://localhost/webportal/organizations/32?qt-organization_tabs=tab1#qt-organization_tabs (where 32 is a variable).
How can I do this using mod_rewite?
Update:
I have updated the URLs above, the URLs originally posted were not correct, anyway I tried the following rule and it is not working:
RewriteRule ^/organizations/(.+)$ ^/organizations/$1?qt-organization_tabs=tab1#qt-organization_tabs [L,R]
All the other rules are working properly, here is the relevant part of my htaccess file (Drupal CMS):
RewriteEngine on
RewriteRule "(^|/)\." - [F]
RewriteBase /webportal
RewriteRule ^/organizations/(.+)$ ^/organizations/$1?qt-organization_tabs=tab1#qt-organization_tabs [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
Thanks
Add this in the htaccess file in your document root:
RewriteEngine On
RewriteRule ^/?webportal/organizations/(.+)$ /pepris/webportal/$1?qt-organization_tabs=tab1#qt-organization_tabs [L,R]
You can also use mod_alias:
RedirectMatch ^/?webportal/organizations/(.+)$ /pepris/webportal/$1?qt-organization_tabs=tab1#qt-organization_tabs

Resources