Trouble with htaccess dynamic redirects on IONOS - php

I am on a Apache server and have created a site with php using a MySQL database on IONOS.
I want to redirect the URLs from /page.php?id=xxx to /page/xxx
I have written a .htaccess file and uploaded it into the root folder. It worked fine until yesterday. I have looked all IONOS support pages and different websites, but I can't find what's the issue.
My htaccess file looks like this:
RewriteEngine On
RewriteBase /
RewriteRule ^page/(.*)$ page.php?id=$1 [QSA,L]
When I try to access the page with /page/xxx, it can't get the xxx id variable.

RewriteBase / is not required in DocumentRoot. Also, your RewriteRule appears to be reversed:
RewriteRule ^page\.php?id=(.*)$ /page/$1 [QSA,L]

Related

mod_rewirte (.htaccess) strange behavior for URLs having ".profile" text

I got a hosting with WordPress engine installed and inside the root of WP engine folders I've created another web application which is having problems with URLs containing .profile word. When this text is added to URL I'm always receiving 404 error.
Here's an example:
WordPress blog URL: https://mainsite.com
Sub web application folder name: webapp
Sub web application access URL: https://mainsite.com/webapp/
So, when I try to access URL like this: https://mainsite.com/webapp/login.php?code=user.profile I'm receiving error 404. At the same time URL like this: https://mainsite.com/webapp/login.php?code=user.profilb is working fine (2nd URL got last letter replaced by another symbol).
I think this is an issue with WordPress default mod_rewrite settings, here they are:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I got no clue at all why this could happen with .htaccess file like this. Could you suggest please?
It turned out that the issue was with mod_security of a2hosting. They were blocking all sensitive linux files and folders, like: .profile, .htaccess, .bashrc...
Hope, this will help someone.

Moving wordpress site from hosting to localhost for development

After moving website to my local dev machine, relative links stopped working. When i click button with relative link /login, for example, browser redirects to
https://localhost/login/
and shows
Code: Not Found
The requested URL /index.php was not found on this server.
While it should have redirected to https://localhost/сс/login/
.htaccess contents on localhost:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cc/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /cc/index.php [L]
</IfModule>
Website files are in var/lib/html/cc folder.
SiteURL and HomeUrl
are both equal to http://localhost/сс
Parmalinks setting http://localhost/cc/sample-post/ is used, so no problem with navigating to pages.
How to fix this issue?
Tried different .htaccess modifications, moving index.php to /var/lib
Nothing helps.
just use WP Migrate DB plugin for database export , it will change all link to your desire link and use this database export file in live site
Link ( https://wordpress.org/plugins/wp-migrate-db/)

Not able to redirect my pages to index.php in WAMP SERVER

I have copied my code from LINUX (which is perfectly working) to Windows where I am using WAMP server to practice web development. I don't understand why my pages are not being redirected to index.php.
dev.mysite.com is working and showing my home page, which means doc root is correct and working fine. Later pages are showing 404 because of this redirect issue. Below is my .htaccess, can someone please check and advice, where I am doing wrong?
For example, if I am trying to access dev.mysite.com/contr1/action1 I am getting 404 not found.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(\d{4})/(0?[1-9]|1[0-2])/([^/]+)/?$ app/$1-$2/$3 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
For Local Development servers you cannot use tld's like .com, .org, .net, etc. without doing additional very complex things, which I will not go into. See this well explained tutorial on setting up Virtual Hosts, hosts file, etc. in WAMP: https://john-dugan.com/wamp-vhost-setup/

Laravel Apache URL mapping

I currently use laravel 5 for web development. And my goal is to upload the website which I made in laravel to a shared host.
But if I upload my files to the public_html folder, I'll have to navigate to mywebsite.com/public/mypage to access a route mypage. Which is not what I want.
I would have just changed the the name of public folder to public_html and then shifted all other folders to the root directory and changed some laravel config options, but that would have made my root directory unclean. So think I would have to use .htaccess for what I want. I am not familiar in using .htaccess, so how would I do this:
If the user enters mywebsite.com/mypage in the browser he gets to see the page mywebsite.com/public/mypage in the browser, but the url in the browser stays the same.
Thanks, in advance.
I also got the same problem when hosting my website in shared hosting godaddy.
I also used laravel5 frameowork and launched the site http://www.hahafunnyjokes.com
Edit the .htaccess file in the root folder where your public_html pointing
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.examplecom/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Thats it, I got my site up and running.
Replace example.com with your website name

htaccess mod_rewrite redirect to directory without displaying on url

I have a site called www.example.com and I have my php files in it. I store all my working files in www.example.com/site. I want to view the site in www.example.com instead, without moving my site content. What can I do?
This is currently what I am typing in .htaccess. It will redirect my site to www.example.com/site but I think the url is ugly
RewriteEngine on
RewriteBase /
RewriteRule ^(/.*|)$ /magento$1 [NC,L]
Let me see if i understood this correctly.
You have a domanin, www.example.com, and on this domain you want to display the content of a directory, www.example.com/site !?
If this is the case then you need to change the document root
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !^/site
RewriteRule ^(.*)$ /site/$1 [L]
or
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ /site/$1 [L,NC]
There are 2 things you must consider :
If I understand your request, you are accessing some PHP files using www.example.com, but what you want is to access www.example.com/site, but without the /site, right ?
So basicaly, what you're looking for is NOT rewrite, it's just pointing your domain to the good folder, which is /site, right ?
If you're using Apache2, you have to edit your apache's configuration file in /etc/apache2/site-available/default (or remplace default with the name of the virtualhost you may have created).
In this file, look for the directive DocumentRoot. It should lead to the "root" directory of your pages (the one you access typing www.example.com)
I think you just have to append /site to this DocumentRoot and then reload your apache2 with service apache2 reload
You're website www.example.com will now lead to the correct directory.
If it's still not working, you must consider looking into magento's admin, because magento is rewriting url according to the Base URL you specify inside Admin / Configuration / general / web.
You'll have to modify Base_URL in both Secure and Un-Secure sections.
Then it should work fine.
I would comment out the Rewrite bloc you're using at the moment, or maybe I didn't fully undestand what you want to achieve.

Categories