php: move the sitemap.xml into folder - php

There is a website having the multi-language functionality archieved by the .htaccess file.
I have generated the sitemap.xml file and I can access it with sitename.com/sitemap.xml
Having a little experience in php, I would ask how can I 'move' the .xml file into a place so that I can access it via sitename.com/ro/sitemap.xml ?

You can just keep sitemap.xml in root folder and add this rule in DocumentRoot .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^ro/(sitemap\.xml)$ /$1 [L,NC]
Now you can use this URL as http://sitename.com/ro/sitemap.xml

Related

Having multiple htaccess in a root directory

I have directory in my website where user can upload projects or create sub directories, in the root dir i have a default .htaccess file and default.php which i don't want the user to get access to because i rewrite the dir to load default.php as default index page and also this to file will be copied to any sub dir that the user create.
Now my problem is when user try to save .htaccess for the project he want to save it will show that is already exist. is there anything i can do to have multiple htaccess or write my own as default htaccess.
Second. is it possible to use one htaccess in all the sub dir so user can freely add their own?
Example: bellow is how my directory look
WWW.example.com/ project /userprojectname/sub1/sub2/sub3/etc...
In project it has htaccess and users are not allow to do anything but their projectname will save there.
In userprojectname it has an htaccess and default.php, they can also add more file or create directories and any sub dir will also have it own htaccess and default.php.
Now can i make htaccess in project work in all page? and as for default, i used jquery to disallow users creating file name default.php also is there a better way i can fix all this?
Bellow is my dirs and htacess file
Options +FollowSymlinks
RewriteEngine on
#This will block from accessing root folder
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9]+)$ $1.php [NC,L]
DirectoryIndex default.php

Making server redirect to another folder with .htaccess

Can i make a htaccess file that redirect from the root of my project to another folder.
So if i usually write 192.168.1.39/public to get to my library where i store the files that i want the users to see.
I would like to only write 192.168.1.39 instead.
Can you do that with a .htaccess file?
In the htaccess file in root, add this rule :
RewriteEngine on
RewriteRule ^$ /folder [NC,L]
^$ matches the hompage and rewrites it to the folder.

Cakephp 3.0: rewrite .htaccess rule to allow new folder access?

I'm using cakephp 3.0 and I'm facing a problem. I upload my site on server on root level, where I place some demos which I can use for other purpose. Now issue is that when I access my site with domain name then it is working fine. But if I give any folder name which is placed on root level which is not the part of my site and is indiviual part of site. Then it is not accessible.
Below is my folder structure of root level
There a single folder named gallery is a demo. How can I allow this folder to access like this http://hostname.com/gallery or any other new folder.
My .htaccess file code is:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Please help me on this issue which is more appreciable.
Thanks in advance.
Just move your "gallery" folder under "webroot".
Try this it's worked for me.
create the .htaccess file in "gallary" folder with following content.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
</IfModule>
and try with URL http://server_name.com/gallary
You have access for that folder and files.
Thanks.

URL Rewriting .htaccess

I'm having some problems with the .htaccess file. I'm working on a REST API and I'm rewriting my URL's, if I put .htaccess at the root of my server (localhost) everything works fine, but I actually don't want to put my .htaccess file there but in my project directory.
For example I want to type
http://localhost/myproject/player/id/etc..
and not just
http://localhost/player/id/etc...
The problem is that if I use
http://localhost/myproject/player/id/etc..
The redirection works correctly but in my controller.php file the Path variable I retrieve is /myproject/player/id. Is there a way to remove /myproject/ from the URI in the .htaccess file, or more generally is it possible to remove the directory of the folder containing the .htaccess from the REQUEST_URI variable ?
ok. try this- in your .htaccess write-
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^myproject/(.*)$ /$1 [L,NC,R]
it will remove myproject from your url.

How to hide a specific file in Code igniter / PHP?

I have a web project and i have created an external photo library for my project.The photo library is outside the web root directory e.g My Codeigniter project is in C:\wamp\www\myprject\application\ but my photo library is under C:\wamp\www\myprject\Lib\
My .htaccess file (under my application folder ) successfully displays the library using the commands below:
.htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|images|Lib|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php?$1 [L]
But the problem is this .htaccess file is also displaying my error_log file along with all the images in the library directory.
What changes i will need to make in this .htacess file to hide it?I just want to display (.jpg,gif,.bmp,.jpeg) files.Please help.Thanks
Do workarounds with 'FilesMatch' tag.
Add this after your RewriteCond and RewriteRule:
<FilesMatch "Lib\.(htaccess|htpasswd|ini|log|error_log|error|sh|inc|bak)$">
Order Allow,Deny
Deny from all
</FilesMatch>
Note: please add your error log file's extenstion in between the pipe ' | ' symbols. Also please remove extensions that you don't want.
More info: How to hide certain file type using apache .htaccess?
I'm not an .htaccess guru, but you should be able to change it to:
## NOT TESTED ##
RewriteEngine on
RewriteCond $1 !^(index\.php|images|Lib\/*\.jpg|Lib\/*\.gif|Lib\/*\.bmp|Lib\/*\.jpeg|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php?$1 [L]
Lib\/*\.jpg is a regex for any jpg file under the Lib directory

Categories