IIS Version 8.5 for Windows Server 2012 R2 Version 6.2
This .htaccess rule which is working on my local dev which is wamp
RewriteRule ^.*search/?(.*)$ /displayPage.php?page=search&%1 [QSA]
I am importing this into an IIS server and it is rewritten as:
Rewrite ^.*search/?(.*)$ /displayPage.php?page=search&{C:1}
Now when I submit my search the url displayed is:
http://example.com/search?keyword=sample+text&cat=1
The page loads a 500 error. When I disable the rule I get a 404 error.
When editing the rule, the Append query string is checked.
So I added a var_dump and echo with an exit just to verify if it reaches the displayPage.php. It did not.
So the rule that was imported does not seem to be configured correctly. How can I fix it?
SOLUTION:
Open the edit rule window in IIS
select the test pattern button
In Test pattern window in field Input data to text: search/?keyword=test+sample&cat=123
The result displayed R:1 = ?keyword=test+sample&cat=123
So Modify the rule from {C:1} to {R:1}
Refresh page and the magic continues!!!
The Rewrite URL is now as follows: /displayPage.php?page=search&{R:1}
Related
I try to rewrite some of my URLs with a .htaccess file but it didn't work as expected.
This is the rewrite rule in my .htaccess file :
RewriteRule ^(index|administration)/([A-Za-z0-9-]+)(\.php)?$ index.php?c=$1&t=$2 [QSA]
When I go on www.example.com/index/main, I get a 404 error code.
So I try to change my rewrite rule to
RewriteRule ^index.php$ index.php?c=index&t=main [QSA]
Then I go to www.example.com/index.php and the webpage displays perfectly with all the datas in $_GET (c = index and t = main).
So I don't know why my first rule is not working. Let me see if you have any idea.
Is it possible that my server wants to enter the index folder, then the main folder for my first rule without taking care of my .htaccess (www.example.com/index/main) ?
You need to ensure that MultiViews (part of mod_negotiation) is disabled for this to work correctly. So, add the following at top of your .htaccess file:
Options -MultiViews
If MultiViews is enabled (it's disabled by default, but some hosts do sometimes enable this in the server config) then when you request /index/main where /index.php already exists as a physical file then mod_negotiation will make an internal request for index.php before mod_rewrite is able to process the request. (If index.html also exists, then this might be found first.)
(MultiViews essentially enables extensionless URLs by mocking up type maps and searching for files in the directory - with the same basename - that would return a response with an appropriate mime-type.)
If this happens then your mod-rewrite directive is essentially ignored (the pattern does not match, since it would need to check for index.php) and index.php is called without the URL parameters that your mod_rewrite directive would otherwise append.
it perfectly works by disabling the MultiViews Option in my .htaccess
This would ordinarily imply its your script (ie. index.php) that is triggering the 404 (perhaps due to missing URL parameters?), rather than Apache itself?
However, if you were seeing an Apache generated 404 then it would suggest either:
You also have an index.html file, which is found before index.php. .html files do not ordinarily accept path-info (ie. /main) so would trigger a 404.
OR, AcceptPathInfo Off is explicitly set elsewhere in the config, which would trigger a 404 when the request is internally rewritten to /index.php/main (by mod_negotiation).
I changed my website from .asp pages to Joomla which uses .php. The page structure has not been maintained. Now, I would like to have all traffic coming in from the indexed .asp pages (by the search engines) redirected to the home page of my site.
I have used the following Rewrite rule
RewriteRule \.asp$ ^/index.php [R=301,L]
but the rule redirects to
https://example.com/home/example/public_html/index.php?key=1234
How can I simply remove the /home/example/public_html/ and also the ?key=1234 parameter while performing the redirect. Or simply saying, how can I just have the redirect go to the home page of my new site.
Thanks.
First see this picture from Apache below :
So , a substitution could not contains Regular Expression as you did here ^/index.php this ^ should be removed first then see what you want to do .
https://httpd.apache.org/docs/2.4/rewrite/intro.html
Replace your code by this :
RewriteRule \.asp$ http://example.com? [R=301,L]
I put ? after example.com to prevent query string like key=1234 to be appended in new target .
Note: clear browser cache then test it .
I'm a beginner.
What I want
the request URL .../activity/1415/abcdefgh/ to be rewritten to .../activity/gallery.php?k=abcdefgh
but still display the URL to the visitor as .../activity/1415/abcdefgh/.
But when I try, the URL .../activity/1415/abcdefgh/ turned to .../activity/1415/abcdefgh/?k=abcdefgh.
The page displays fine, but I want to hide the query.
Basically what happened
Link says: http://localhost/activity/1516/iolfpqwx
Clicked link
Address bar says: http://localhost/activity/1516/iolfpqwx/?key=iolfpqwx, which I don't want.
My entire .htaccess in the activity/ directory:
RewriteEngine On
RewriteRule ^(\d{4})/(\w{8,})(?:/([\w\s]+)?)?$ gallery.php?key=$2 [L,QSA,NC]
My Specs:
XAMPP on Windows with Apache
What I know
I have not setup any redirect rules on my testing server, so I don't believe I have any [R] flags.
I have a similar .htaccess in an adjacent directory with the code RewriteRule ^settings/([^/]+)/*$ index.php?p=settings&s=$1 [L,QSA,NC] and it didn't show me query strings.
I've Googled my issue, but cannot find a solution. Please help.
I have created the new magneto site and importing the data from the old site but I have the problem with the URLs.
Old site URL starts from wwww.sitename.com
but in my new site it starts from sitename.com without www.
Now I am trying to add WWW in my magento site or remove the WWW from the old site through .htaccess file
but the problem is when I change the magento site bse URL to www.sitename.com it is giving server not found error
I have also used the htacess rule to remove the WWW from the old links?
any hint regarding this issue ?
1 ) System > Configuration > Web > Unsecure and Secure
Check correct url are setup or not. (www)
2) .htaccess changes :
RewriteCond %{HTTP_HOST} ^yoursitename.com$
RewriteRule (.*) http://www.yoursitename.com$1 [R=301]
If you have access to the database, the table you could edit is core_config_data and the values you need to change are in the path column. Change the web/unsecure/base_url and web/secure/base_url to match the new domain name by altering the value column for both records
I'm looking to 301 redirect an URL from a old version of a site no longer being used to a new URL that has been created in fresh Drupal installation.
Old URL: /198/our-software/
New URL: /services/software-development/
In the .htaccess located in the root directory of Drupal I have added the following:
redirect 301 /198/our-software/ http://www.domain.com/services/software-development
The redirect is working to some extent, it sends the user to a url like below with a query string appended to the end of it, which results in a 404 error:
http://www.domain.com/services/software-development?q=198/our-software/
I have tried placing the redirect at both the start and end of the .htaccess file both result in a 404 page not found error.
Do I need to use a more complex redirect to get around Drupals URL rewrite?
NOTE: I'm using the Pathauto module.
Rather than edit the .htaccess directly, just install the Path Redirect module which has that exact functionality built in.
Note that the Path Redirect module is only available for Drupal 6 (as of 2/22/12)
I got it working with using "RewriteRule" instead, AND (important!) removing the leading slash in the source URL, so in your case:
RewriteRule 198/our-software/ http://www.domain.com/services/software-development [R=301,L]