How to change the project name in CakePhp 3.x - .htaccess

I have this project called 'site01'.
It is published as: 'www.example.com/site01'. The pages are like this 'www.example.com/site01/page/1'.
I'm able to route the url to 'www.example.com/site01/1', but can I change the url to 'www.example.com/s/1' through the routes configuration?

Initially I think that you have to use .htaccess way, because the issue is related to the outside of the CakePHP folder.
You can create a new file named .htaccess in the upper folder and write the instruction witch redirect /site01/ to /s/.
sample code for rewrite url:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^site01.*$ /s/ [R=301,L]

Related

Htaccess and redirect all content of folder, but exlude the main folder

I got the following urls:
domain.com/categoryA/articleA
domain.com/categoryA/articleB
I want to redirect:
domain.com/categoryA/articleA -> domain.com/categoryB/articleA
domain.com/categoryA/articleB -> domain.com/categoryB/articleB
but leave it as it is and do not redirect the main folder: domain.com/categoryA/
I tried to use the rule:
RewriteRule ^categoryA/(.*)$ /categoryB/$1 [R=301,NC,L]
but it also redirect domain.com/categoryA/ to domain.com/categoryB/
How to exclude from the above rewrite rule the redirection of the main folder (categoryA), but still redirect all that is in the folder (and then change also the root folder)?
I am looking for a solution that is SEO friendly (I got the same articles in two categories, but want still to have indexed domain.com/categoryA, but the rest only as domain.com/categoryB/xxx.
Best Greetings,
Mat
With your shown samples/attempts, please try following Rules in your .htaccess file. Please make sure to place this rule under your domain redirect rule(if its there), also make sure to clear your browser cache before testing your URLs.
RewriteRule ^categoryA/([\w-]+)/?$ /categoryB/$1 [R=301,NC,L]

Redirect existing second page to non-existing url

I have a site https://sitename.com/web (example). So, full path to page is sitename.com/web/index.php. On ftp server there is folder /web which also contain second page file - index-2.php. How to avoid creating /web-2/ folder and redirect index-2.php to sitename.com/web-2 ?
Easy, create an .htaccess file inside the root folder of your site, then add the following lines to it:
RewriteEngine On
RewriteRule ^web-2$ index-2.php [QSA,L,NC]
This site might help you with htaccess:
https://www.htaccessredirect.net/
A nice tutorial on .htaccess files also below:
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file

Setup website with / prefixed URLs to run in sub-directory

I am trying to host a website that is setup with links in the format /css/file.css and /js/file.js and I'd like to set it up in a sub-directory on an existing domain for demo purposes.
So
/demo/css/file.css is the true path
But the demo/index.php references
/css/file.css
I can have a custom .htaccess file within the sub-directory.
Is this possible without touching the main site on my domain?
If the request is for /css/file.css then rules have to be placed in root .htaccess not in /demo/ directory.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^((?:css|js)/.+)$ /demo/$1 [L,NC,R=302]

Website pages with slashes

Just building a site using php. I would like to know how to create pages without having to make ".php" links for every page. For example I want to build the site to be as follows: www.mysite.com/products instead of www.mysite.com/products.php. (Further example www.mysite.com/products/headphones )
An example of what I am looking for is as follows: http://www.starbucks.ca/store-locator
Any idea how starbucks is doing this? It isn't making a separate folder and index for every page is it?
Thanks in advance!
Jason
You can use URL rewriting to do this. You can create a .htaccess file, place it in the root directory of your website with the following content (as an example):
RewriteEngine On
RewriteRule ^tutorial/([0-9]+)/$ index.php?tutorial=$1
RewriteRule ^page/store-locator/$ index.php?page=store-locator
RewriteRule ^$ index.php
These are some basic rules that tell the web server to rewrite a URL without .php to a URL that does have .php.
In the above example, when you are visiting example.com/tutorial/3/, it will actually visit example.com/index.php?tutorial=3 and then your index.php will display the contents. It's similar for the store-locator page.

url rewriting asp .htaccess file

I just moved my website (asp.net) to the live environment. I realized they are running IIS 6 so all my nice and clean url rewriting doesn't work anymore. I was trying to implement URL rewriting using the .htaccess file.
I want to rewrite:
www.amicobio.co.uk/Menu.aspx to www.amicobio.co.uk/Food-Menu
So in .htaccess I set:
CaseInsensitive On
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^Food-Menu$ Menu.aspx
But it doesn't work it says:
The requested URL
/a/m/amicobio.co.uk/public/Menu.aspx
was not found on this server.
Obviously the path is wrong but what is /a/m/ and how do I fix it? All the files in amicobio.co.uk/public/
Thanks.
I found the solution
it was
RewriteRule ^Food-Menu /Menu.aspx
in stead of
RewriteRule ^Food-Menu$ Menu.aspx

Resources