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¶ms=$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¶ms=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¶ms=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?controller=$1&cmd=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?controller=$1 [L,QSA]
Related
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]
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]
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
So I'm using .htaccess to redirect old site pages to new site pages. A typical rule in my file looks like this:
Redirect 301 /faqs.php http://blueprintprep.com/classroom/faq
Strangely, it works fine when the old file exists on the server, but when I remove the file, the final URL actually looks like this:
http://blueprintprep.com/classroom/faq?/faqs.php
What in the blue blazes is going on??
The file is made up of a bunch of these rules and this for CodeIgniter:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^application_consulting/(.*) http://blueprintprep.com/oneonone/app_consulting [R=301,L]
RewriteRule ^weekend/(.*) http://blueprintprep.com/classroom [R=301,L]
RewriteRule ^workshop/(.*) http://blueprintprep.com/oneonone [R=301,L]
You can use mod_rewrite instead.
RewriteEngine on
RewriteRule ^/faqs.php$ /classroom/faq [L,R=301]
This will work regardless if the file exists or not.
Hope that helps.
This is my .htaccess file
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# Force add trainling slash
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ http://foo.bar/$1/ [R=301,L]
# Prepent www if not exist in URI
RewriteCond %{HTTP_HOST} ^foo\.bar$
RewriteRule (.*) http://www.foo.bar/$1 [R=301,L]
# If path is not a directory or file then apply RewriteRule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite for profile view
RewriteRule ^([^/]+)/?$ profile.php?user=$1 [NC,L]
# Rewrite for page view
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ account.php?type=$1&user=$2&page=$3 [QSA,L]
# Condition to ignore regular links
RewriteRule ^library/templates/([^/]+)/([^/]+)/([^/]+)/?$ library/templates/$1/$2/$3 [QSA,L]
# Rewrite for dynamic page settings
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ account.php?type=$1&user=$2&page=$3&$4=$5 [QSA,L]
# Rewrite for account view
RewriteRule ^([^/]+)/([^/]+)/?$ account.php?type=$1&user=$2 [QSA,L]
# Rewrite for site default resources location
RewriteRule ^([^/]+)/([^/]+)/theme/s/([^/]+)/([^/]+)/([^/]+)/?$ library/themes/site/$3/$4/$5 [QSA,L]
I know this is kinda not the best way to go about this, feels like there is too much redundancy but I'm no expert but its working for me. If anyone can give me advise on how to make this more efficient I would highly appreciate it.
Ok so my problem is that I have a real directory at
www.foo.bar/path/to/real/dir
and I want to access a file in that directory, but my rewrite rules aren't letting access that directory unless I make a new rewrite rule redirecting my url to itself.
Check for files symlinks and directories as well (as your first rule):
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC,OR]
RewriteCond %{REQUEST_FILENAME} -l [NC]
RewriteRule .* - [L]