How can I use .htaccess to make this URL
http://domain.com/index.php/sub1/sub2/333
look like
http://domain.com/333
?
Thank you very much!
I tried everything and I tried to find everywhere the answer, but nothing works.
This is my htacces, maybe can help you ( I hosted in hostgator,in hostgator is importan write your user, if is local remove ) this configuratio apply to multiple sites
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /<myuser>/%{HTTP_HOST}
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /<myuser>/%{HTTP_HOST}/index.php/$1 [L]
</IfModule>
You can replace %{HTTP_HOST} by your folder.
After if you want modify the controller name, you need modify in application/config/routes.php
Following rule should work for you:
RewriteEngine On
RewriteRule ^([0-9]+)/?$ /index.php/sub1/sub2/$1 [L]
Related
I have been looking for many tutorials bu no one has really helped me, I know you guys can:
My website has the following structure:
mywebsite.domain/?pg=somepage
But I would like to leave it like this:
mywebsite.domain/somepage
All the tutorials I have found work in the next structure:
mywebsite.domain/file.php?pg=somepage
So I can't gess how a RewriteRule would be using my structure.
I have tried:
RewriteEngine on
RewriteRule ^index/([0-9a-zA-Z]+) index.php/?pg=$1
And also:
RewriteEngine on
RewriteRule ^index/([0-9a-zA-Z]+) index.php?pg=$1
But I have had no luck :(
Note: My index file has .php extension
You could do something like this -
RewriteRule ^(.*)$ /index.php?pg=$1 [L]
This will redirect mywebsite.domain/somepage to mywebsite.domain/index.php?pg=somepage
or full config -
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?pg=$1 [L]
</IfModule>
for more info - Apache mod_rewrite
Okay so i'm working on creating a thing to delete images from my server. I figured out about the unlink function and have turned it into a get variable. How can I use htaccess to delete a file from my server with a url like this example.com/imagename/delete
RewriteRule ^/delete/([^/]+)$ index.php?delete=$1
I realized that this does /delete/imagename but I want the urls to be /imagename/delete. I tried the following but that didn't work.
RewriteRule ^/([^/]+)$/delete index.php?delete=$1
I know this sounds simple and easy to find on the web but I can't seem to find this!
Change your rules to
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^([^/]+)/delete/?$ index.php?delete=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.png [L]
I'm sure this has been asked in other forms, but I can't for the likes of me get this thing working after googling/trying for hours.
I have a bunch of URLs like this:
www.yoursite.com/pic_box.php?pic=$
What I want is that all URLs will only be avaiable with clean URLs.
www.yoursite.com/your-title-here
Can any htaccess master help me with this?
In your .htaccess:
RewriteEngine on
RewriteRule ^picbox/(.*)$ /pic_box.php?pic=$1 [NC,L]
Will give you the ability to rename your url like that:
www.yoursite.com/picbox/your-pic-id
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /pic_box.php?pic=$1 [L]
Having some issues with .htaccess on my website. I'm trying to alter the suffix of the URLs for my website. URLs currently appear as:
www.example.com/about.phtml
I want to remove about.phtml and replace it with about so it looks like:
www.example.com/about
The examples I'm using are not what I need on the website so I would like code that I don't have to go through and specify which specific page to remove it from and rather do it all automatically.
I've tried using php instead of phtml with no luck. Here is the code I am using:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.phtml -f
RewriteRule ^(.*)$ $1.phtml
Any ideas what I am doing wrong here?
FYI: my host is JustHost and they allow me to edit my .htaccess but if anyone has heard of or had any problems with them please let me know, I spoke to their tech-support who couldn't help me any more than I can help myself.
Try this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.phtml [NC,L]
This works for me:
RewriteEngine on
RewriteRule ^/?([a-z]+)$ $1.phtml [L]
You can Check first your rewrite mode is on or not in apache\conf\httpd.conf file
check below code in httpd.conf file
#LoadModule rewrite_module modules/mod_rewrite.so
if hash exist in above the line then remove hash and restart apache server
After then you can set below code in your cakephp httaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.phtml -f
RewriteRule ^(.*)$ $1.phtml [NC,L]
</IfModule>
Currently, my .htaccess file looks like htis:
IndexIgnore */*
RewriteEngine on
RewriteRule ^add /add.php
RewriteRule ^add/$ add.php
RewriteRule ^sitemap.xml /xmlsitemap.php
RewriteRule ^([^/\.]+)$ /index.php?slug=$1
RewriteRule ^([^/\.]+)/$ /index.php?slug=$1
It works fine for links as: site.com/category/
However, i would like the complete slug after site.com/. So that i can redirect site.com/category1/subcategory2/subsubcategory3 etc. There can be an unknown amount of subcategories inside a category.
I tried with request_uri but that didn't really work out.
How to do this? Thanks a bunch!
EDIT:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* slug.php?%{QUERY_STRING} [L]
this will pass URL to slug.php
ok, got it. it's simply: deleting the ^/. from the regex. i just figured that means that it has to stop at any / :) but... thx! it works now! :)