HTACCESS RewriteRule - Not sending query string from Pretty URL - php

I am having trouble with the RewriteRule. I have created a pretty URL for my search page where it posts to itself to query the results. However the $_GET['type'] variable is not being sent to the page. This works perfectly fine on my local WAMP server but does not return a result on my Live hosted server.
e.g. http://..com/search/searchType/ SearchType being the $_GET['type'] data I am sending to the page.
My .HTACCESS is as follows
RewriteEngine On
RewriteRule ^property/(.*)/(.*)/([0-9]+)/$ view_property.php?type=$1&id=$3 [L]
RewriteRule ^search/(.*)/ search.php?type=$1 [L]

The problem is because there is a conflict with the file name search.php, which broke the RewriteRule which started with the text 'search'.
After discovering this and doing more research I found that including Options -MultiViews which disables the mod_negotiation MultiViews.
This must have been enabled on my Live hosted server and disabled on my local host. I will find out and update shortly.
Another fix is to rename the RewriteRule URL to something other than ^search/ or any other name that currently exists as another file to remove this conflict.

Related

.htaccess rewrite rule is only working when .php is in the URL

I have the domain example.com with several external domains pointed to it in different directories.
I have the following RewriteRule
RewriteEngine on
RewriteMap urlmap txt:/var/www/html/map.txt
RewriteRule ^(.*)$ ${urlmap:%{HTTP_HOST}}/$1
The problem with this is that I cannot open files without adding the .php extension to the end of the URL.
For example, cool.com points to example.com/someuser and that works fine - probably because it automatically points to index.php.
If I choose to visit cool.com/file, I am greeted with a 404 error:
The requested URL /someuser/file.php was not found on this server.
However, if I choose to visit cool.com/file.php, everything works perfectly for some reason.
How could I fix this?

after changing the wordpress adress and site address in localhost xampp then it not working anymore

I am new in creating a website using wordpress. I am using xampp to create a local wordpress website and my website run under: localhost/mysite. I want to import my local website to my live website https://vsaftest.wordpress.com/ by going to the setting of my local website and then changed the wordpress Address and site address from http://localhost/mysite to https://vsaftest.wordpress.com/. After that then I can not access to my local site using http://localhost/mysite anymore, and inside the website https://vsaftest.wordpress.com/ there is nothing there also. I know that I made a mistake here but then anyone can help me how can I change back so that I can access my site from localhost :(
I've never used Wordpress before, but going purely from your desription, you seem to think that changing a setting on and for your local machine will somehow affect the settings on a remote machine.
and inside the website https://vsaftest.wordpress.com/ there is nothing there also
But was there nothing there beforehand either? In other words; Nothing's changed?
I think the reason you cannot view your local site anymore is precisely because you made the change you said you did. Instead of its changing the remote machine (which it probably doesn't do...I don't do WP dev, so I don't know for sure) it changed your local machine.
Can you not just change wordpress Address and site address on your local site back to what it was before?
There are many pitfalls one might encounter when moving a Wordpress website from a local development environment to production. Here are the main things to remember and look out for.
Htaccess
When developing in Xampp it's very common to include the website's directory name in the .htaccess' RewriteBase and RewriteRule. Assuming your production website will be situated in the root directory you'll want to remove the directory references from your .htaccess file.
For example your development .htaccess file might look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mysite.com/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mysite.com/index.php [L]
</IfModule>
# END WordPress
But in production you'll need to adjust it to look like this:
# 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
One good development practice you can adopt is creating .live and .dev htaccess files. Create .htaccess.dev and .htaccess.live files and store your development and production htaccess data in them respectively. Your real .htaccess file will then contain the current active data and you can easily copy/paste from the .dev and .live files to it if needed.
Database
When you move a Wordpress website to production you must also create a production database for it. Make sure the database created has the same collation as the development one and that the database credentials in your wp-config.php file are updated to reflect the production database user, password, etc. Remember that if your WP_DEBUG variable is not set to true database errors will not be shown if a database connection error occurred in your production website. Because of that database errors in production more often than not lead to a "white screen of death".
Another thing one must make sure (and you already mentioned in your question) is that the siteurl and homeurl keys in your wp_options table are updated to reflect the production website url. In case multiple domains exist (for example .com and .co) one can enforce the correct url by defining the WP_SITEURL and WP_HOMEURL constants dynamically within the wp-config.php file.
PHP version
Last but not least, make sure the PHP version required for your website is compatible with the production server's PHP version. 2017 is a transitional year in terms of PHP support. Whereas Xampp already supports PHP 7 sadly many servers still do not.

Mod-rewrite not working on Network Solutions server

I have a website that requires mod-rewrite to function well, but it seems to not be functional on the Network Solutions shared server we're running on. Network Solutions promises it's installed but won't provide any further support without additional payment.
I placed a simple test at the following folder which contains two files. The first, ".htaccess" contains the following text:
RewriteEngine On
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]
The second is the PHP script which tests it, available here:
http://www.oceanhousefloridakeys.com/testmr/rewrite.php
All I see is that mod-rewrite is installed (no error messages showing) but the rewriteRule is not working. Can anybody see why this script isn't working... is there anything I can do to get it running, or is Network Solutions not telling the whole truth?
It looks like your script resides inside a sub-directory. In that case it's the best solution to set the RewriteBase to the correct path (before any RewriteRule):
RewriteEngine On
RewriteBase /testmr/
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]

.htaccess method of setting a default URL to resolve to?

We have two sites, and we've just now made an in-house development server that we want to have both sites on. What I want to accomplish is to have an .htaccess in each of the site folders that prepends the development URL of the site. For example, where they simply have a header(location: /folder/whatever.php), the files should actually go to thesite/folder/whatever.php.
Currently what happens is (for example) they'll go to 192.168.x.x/folder/whatever.php
If I understood correctly and what you want is to redirect 192.168.x.x/folder/whatever.php to thesite/folder/whatever.php, you could use this:
RewriteCond %{HTTP_HOST} !^thesite.com$
RewriteRule ^(.*)$ http://thesite.com/$1 [R=301,L]

.htaccess 404 page not found

I'm writing my own url shortener. I'm done with everything such as creating short urls. But when I try to browse htt p://example.com/rtr93, I get a 404 error. But http://example.com/index.php/rtr93 works find and shows the relevant page (I'm not redirecting to a new url. I'm just getting the relevant record from database which has a column short_url).
I'm using PHP and syfmony 1.2 if that helps. I think I need to properly setup .htaccess file. But I don't know where to get started.
Something like this should work:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ /index.php [L]
You may want to make the regex more specific if you're planning on hosting other things on the same domain.

Categories